In `shap.plots.scatter` for a readmission model's length-of-stay column, what does vertical spread mean, and what does `color=shap_values` add?
answer
- feature value against its own SHAP value
- same x, different y
- colour by a second feature
- approximate_interactions picks it
- a binned heuristic, not exact interactions
basics
~20 sA shap scatter plots each patient's length of stay against its SHAP value. Vertical spread at one length of stay means other features change its contribution; color=shap_values colours dots by the feature shap's heuristic ranks as interacting most.
solid answer
~40 s`shap.plots.scatter(sv[:, "length_of_stay"])` puts the feature's value on the x-axis and its SHAP value on the y-axis, one dot per patient, with a light histogram of the feature underneath. If the model used length of stay on its own, patients with the same stay would get the same SHAP value; **vertical spread** at one x value is the interaction cue. Passing `color=sv`, the whole Explanation, asks shap to colour dots by the feature that `shap.utils.approximate_interactions` ranks highest: a heuristic that correlates this feature's SHAP values with each other feature within windows along length of stay. If short stays split into red-high and blue-low age bands, age is modulating the effect. I treat that as a lead to check, for instance by colouring with `color=sv[:, "age"]` explicitly, not as a measured interaction.
go deeper
Recall the axes: the feature's value across, its SHAP value up, one dot per patient.
Explain why points at the same feature value can have different SHAP values and what the default colouring and histogram show.
Show you can read an interaction cue from color=shap_values, know it comes from a binned correlation heuristic, and confirm it with explicit colouring before reporting it.
Decide how interaction findings from attribution plots are worded and validated before they inform clinical or product decisions, given they describe the model only.
## What the scatter plot draws `shap.plots.scatter` is shap's dependence plot. It takes a **single column** of an Explanation, such as `sv[:, "length_of_stay"]`, and draws: - **x-axis:** the feature's value for each patient, from `.data` (or `.display_data` when set); - **y-axis:** that patient's SHAP value for the feature; - **one dot per patient**, coloured `#1E88E5` by default; - **a light histogram** of the feature's values along the bottom (`hist=True`); - **grey ticks on the y-axis** for patients whose feature value is missing. Passing a 2-D Explanation with several columns, such as `sv[:, ["age", "length_of_stay"]]`, draws one subplot per column on a shared SHAP axis. Passing the full Explanation does the same for every feature, so a 30-feature model produces 30 cramped subplots instead of one readable plot. For the readmission model, explained on its log-odds margin, the y-axis is in log-odds. The overall shape shows how the model's use of length of stay changes along its range, for example rising steeply up to about a week and flattening after. ## Vertical spread is the interaction cue If the model's contribution from length of stay depended only on length of stay, every patient with a nine-day stay would have the same SHAP value, and the dots would sit on a single curve. **Vertical dispersion at a fixed x** means something else in each patient's row changes how much the stay contributes. shap's own documentation for the plot names this: vertical dispersion represents interaction effects. Two cautions keep the reading honest: 1. Spread says *that* the contribution varies, not *which* feature causes it. 2. When features are strongly correlated, the explanation can share credit among them in ways that create spread too; whether that sharing is faithful is a separate question from reading the plot. ## What `color=` adds | Call | Colouring | |---|---| | `shap.plots.scatter(los)` | One fixed colour (`#1E88E5`) | | `shap.plots.scatter(los, color=sv)` | The feature that `approximate_interactions` ranks first | | `shap.plots.scatter(los, color=sv[:, "age"])` | Age, chosen by you | With `color=sv`, shap calls `shap.utils.approximate_interactions`, which: 1. sorts patients by length of stay (sampling 10,000 rows when there are more); 2. walks along that order in windows of up to 50 patients; 3. in each window, correlates the length-of-stay SHAP values with every other feature's values, and sums the absolute correlations; 4. ranks the other features by that score and colours by the top one. Its docstring says plainly that it only bins SHAP values along the feature's value. It is a quick screen, not an exact pairwise interaction measure. ## Reading a coloured scatter Suppose `color=sv` picks `age`, and at short stays the red dots (older patients) sit higher than the blue dots (younger patients) while at long stays the colours mix. The reading: for short stays, the model gives length of stay more upward push for older patients. A sound workflow is: - confirm the pick by colouring with the candidate explicitly, `color=sv[:, "age"]`, and with one or two runners-up; - check the reverse plot, `sv[:, "age"]` coloured by length of stay; - report it as "the model treats short stays differently for older patients", never as a clinical effect. ## Common misreadings - **Treating spread as explainer noise.** For a tree model explained with TreeExplainer the values are computed exactly, so spread reflects the model, not sampling. - **Treating the colour pick as proof.** The pick is a ranking from a binned correlation screen; a close runner-up can be the real story. - **Ignoring the histogram.** A dramatic curve over a range with three patients in it is a curve over three patients. - **Forgetting missing values.** Grey ticks on the y-axis are patients with no recorded length of stay; their SHAP values still count in every global view. ## How this differs from neighbouring views - A **beeswarm** collapses each feature into one row of dots coloured by the feature's own value; it shows direction and spread but not the shape along the feature's range. - A **partial dependence** curve averages the model's prediction over the data while one feature is varied; the scatter instead shows each patient's own attribution, which is why it can display spread. - The scatter shows how the **model** uses the feature. It never establishes what changing a patient's stay would do. ```python los = sv[:, "length_of_stay"] shap.plots.scatter(los) # one colour, histogram underneath shap.plots.scatter(los, color=sv) # top approximate interaction shap.plots.scatter(los, color=sv[:, "age"]) # an explicit second feature ```
- Someone calls `shap.plots.scatter(sv)` with the full 30-feature readmission Explanation. What comes out, and what should they pass?Because the Explanation still has every feature column, the scatter draws one subplot per feature, 30 narrow panels on a shared SHAP axis, which nobody can read. Select the feature first, `sv[:, "length_of_stay"]`, or a short list of names for a few side-by-side panels, and keep `color=sv` for the interaction cue.
- The `color=sv` pick changes when you explain a different month of patients. Is that a problem?Not necessarily. `approximate_interactions` ranks features by binned correlations in the batch you explained, and above 10,000 rows it scores a random 10,000, so close runners-up can swap between batches or even between runs. Colour by each candidate explicitly and compare; a stable interaction should show the same pattern in both months.
- Vertical spread in a SHAP scatter is random noise from the explainer.
- color=shap_values colours each dot by its own SHAP value.
- The interaction feature chosen by color=shap_values is an exact Shapley interaction measurement.
- A rising scatter proves that longer stays cause readmissions.
- Grey ticks on the y-axis are outlier patients the plot excluded.