From global importance to individual explanations
Model transparency
An explanation can help us investigate whether a model relies on sensible signals or surprising shortcuts.
Why do we need more than a ranking?
- Global importance asks: Which features does this model rely on overall?
- A person receiving a prediction might ask: Why did the model make this prediction for me?
- The same feature can push predictions up for some examples and down for others.
- We need a local explanation: contributions to one particular prediction.
SHAP: share the credit for a prediction
SHAP = SHapley Additive exPlanations
- Think of the features as players on a team producing a model output.
- Start with a base value: what the model predicts on average for a chosen set of reference examples.
- For one example, allocate the difference between its output and the base among its features.
- Each feature receives a signed contribution, called a SHAP value.
A prediction as a sum of contributions
\[
f(x) = \underbrace{\text{base value}}_{\text{reference output}}
+ \underbrace{\sum_j \phi_j(x)}_{\text{feature contributions for this example}}
\]
Illustrative house-price explanation:
| $300,000 |
+$60,000 |
+$30,000 |
−$20,000 |
$370,000 |
- Positive contributions push the output above the base; negative ones push it below.
- These are contributions to this prediction, not coefficients or renovation effects.
SHAP: what to look for
For one prediction, ask:
- Direction: Which features push the model output up or down from the base value?
- Size: Which features have the largest contributions?
- Variation: How do those contributions differ for another example?
SHAP handles the calculation; we will focus on reading and using the explanations.
Reading a local SHAP explanation
Find the base, the largest positive and negative contributions, and the final output.
In our demo: explain the income score
- Model: fitted LightGBM; class 1 is income
>50K.
- Reference: 100 fitting examples; explain 300 validation examples.
- SHAP explains the raw score in log-odds, not probability.
\[
s = \text{base value} + \sum_j \phi_j(x),
\qquad P(\text{income}>50K) = \frac{1}{1+e^{-s}}
\]
- A positive SHAP value raises the score and therefore the probability of
>50K relative to the base.
- Add contributions first, then convert the total to probability.
From one explanation to a global summary
| Waterfall |
One example: how signed contributions move the base to the prediction. |
| Bar |
Many examples: rank features by mean absolute SHAP value. |
| Beeswarm |
Many examples: each dot is one example’s contribution for a feature; colour shows its feature value. |
A large mean absolute SHAP value means large contributions on average; it does not measure a drop in predictive performance.
Class demo: SHAP
Return to the feature importances notebook, Section 6.
- Check that base + contributions = model output.
- Compare waterfall plots for two different predictions.
- Read the bar and beeswarm plots: what changes when we summarize many examples?
Discuss: Does a high feature value always give the same SHAP contribution?
What SHAP does and does not tell us
- SHAP explains a fitted model’s output, relative to a chosen reference.
- Contributions depend on the example, model, background, and treatment of dependent features.
- A positive contribution does not establish that changing that feature would improve the real-world outcome.
- Use explanations to investigate model behaviour; assess predictive performance and fairness separately.
iClicker: SHAP
Which statements are true? Select all that apply.
- SHAP values are parameters learned when the predictive model is trained.
- The same feature can have a positive SHAP value for one example and a negative value for another.
- SHAP can explain only tree-based models.
- A waterfall plot shows how feature contributions add to a base value to recover one model output.
- A SHAP value of +0.2 always means a 20-percentage-point increase in predicted probability.
Takeaways
- Coefficients: interpret a change in a model input, holding other inputs fixed; account for preprocessing.
- Global importance: summarize model reliance or contribution magnitude; read what the method measures.
- SHAP: explain individual outputs relative to a reference, then summarize across examples.
- Explaining a prediction does not establish cause and effect.