POLS 4728
SHAP
SHapley Additive exPlanations
How do features explain the gap between a prediction and the background average?
Start the explanationPOLS 4728
SHapley Additive exPlanations
How do features explain the gap between a prediction and the background average?
Start the explanation1 / 31 · Start with Shapley
: all features; . We use interventional SHAP.
Scroll to highlight each part, or use Next.
2 / 31 · The observation
3 / 31 · The prediction
4 / 31 · Average background predictions
Interventional SHAP · any prediction model
Keep the features in at their values in . Predict with each background row, then average the predictions.
Use every background row without conditioning on the included values.
: included values from this observation.
: the other inputs from background row .
: number of background rows.
5 / 31 · The feature’s credit
6 / 31 · Bread and Peace
Interventional SHAP
Bread: real income growth. Peace: fewer war fatalities.
Stylized version; variables centered and standardized.
Douglas A. Hibbs Jr. (2000). “Bread and Peace Voting in U.S. Presidential Elections.” Public Choice 104, 149–180.
7 / 31 · Three correlations
8 / 31 · Both features are fixed
This election: , . Inputs to are written in that order.
Use this election’s bread and peace values in the fitted two-feature model.
Predictions: SD of vote share.
9 / 31 · What if only bread is fixed?
= ? Bread in this election: .
Not used for SHAP. We do not refit the model.
10 / 31 · Keep the model; average over peace
= ? Bread in this election: .
Hold bread fixed; use all eight background peace values, without conditioning on bread.
Mean peace is 0. This shortcut need not hold for nonlinear models.
Predictions: SD of vote share.
11 / 31 · Bread first
12 / 31 · Peace first
13 / 31 · The two-feature SHAP values
For bread 1 and peace 1, the two orders give bread the same marginal of +0.5 and peace the same marginal of +0.5. Their SHAP values add to the prediction, 1, from a zero baseline.
14 / 31 · The value-function recap
Interventional SHAP: average predictions
Keep included inputs at this observation’s values; use every original background row for the other inputs, without conditioning.
Linear model: use mean excluded inputs
: overall background means. This shortcut can fail for nonlinear models.
| Bread | Peace | ||
|---|---|---|---|
| Breadbackground mean | Peacebackground mean | ||
| Breadfrom this election | Peacebackground mean | ||
| Breadbackground mean | Peacefrom this election | ||
| Breadfrom this election | Peacefrom this election |
15 / 31 · When features interact
In this model, ability’s contribution depends on neighborhood.
West and East Germany Map: Kunz & Moeschl · IEG-Maps 360 · CC BY-NC 4.0.
16 / 31 · The model and the observation
: the same earnings prediction rule.
For the adverse neighborhood profile, ability is 1, neighborhood opportunity is −1, and experience is 1. The model predicts $30,000 per year.
17 / 31 · The term
Selected observation .
Baseline:$47,000
18 / 31 · The term
19 / 31 · The difference
20 / 31 · The factorial weight
21 / 31 · The sum and its result
22 / 31 · From the formula to the plot
23 / 31 · One common zero
24 / 31 · One person, three dots
25 / 31 · Explain more people
26 / 31 · Make overlap visible
27 / 31 · Add the input values
28 / 31 · Opposing contributions cancel
29 / 31 · Measure distance from zero
30 / 31 · Average the distances
31 / 31 · Rank the averages
Both examples are constructed for teaching. SHAP explains their model predictions; it does not estimate causal effects.
The prediction model stays fixed throughout each explanation. The earnings model has three features: ability, neighborhood opportunity, and experience. The ability–neighborhood interaction is part of the prediction rule, rather than a fourth feature.
The earnings background contains eight equally weighted endpoint profiles, with an average prediction of $47,000. Included features take this observation’s values; the excluded inputs stay together from each reference row. Choosing another person changes the explanation while the model and background remain fixed.
We use interventional SHAP: average over all original background rows without conditioning on the included values. Conditional SHAP uses the excluded inputs’ distribution conditional on those values and can allocate credit differently when features are correlated. More on these background choices.
Removing a feature and refitting would change the prediction model. Our calculation keeps the original model and averages its predictions. Substituting overall background means is a shortcut for linear models; it does not require standardization and can fail for nonlinear models.
Include a column to copy this person’s value into every row. Exclude it to keep the original background values. All three input columns remain in the table and in the model.
The figures illustrate a larger dataset using 125 constructed profiles: five values for each input, with ability and experience from 0 to 1, and neighborhood opportunity from −1 to +1. Each explanation uses the same eight reference profiles, fixed model, and baseline.
Select a profile to see all three contributions together. Selecting a dot in the colored beeswarm opens the same explanation.
Global importance averages each feature’s absolute SHAP values across these profiles:
The bars summarize magnitude, losing the direction and spread visible in the beeswarm. Their ranking describes this model, background, and population; changing the background or population can change the result.
Calculation and reproduction files.
Method references: the prediction game, background replacement, and global importance.