The pizza game had 3 features and 6 orderings to average — already a lot of arithmetic by hand. A real model can have hundreds of features, and grows far too fast to ever enumerate. SHAP — short for SHapley Additive exPlanations — is what makes Shapley values usable in practice — and for one common case, it doesn't need the orderings at all.
A linear model predicting a house's price from four features. Every bar is that feature's SHAP value for this specific house — and unlike the pizza chapter, none of these came from averaging over orderings. For a linear model, there's an exact shortcut.
For a linear model , the Shapley value has a closed form — no permutations needed at all:
- — feature 's SHAP value: its contribution to this specific prediction.
- — the linear model's weight (coefficient) for feature .
- — this instance's actual value for feature .
- — feature 's baseline value, typically its average across some reference population.
- Credit is weight times distance from typical
A feature's credit is just its weight times how far this instance sits from "typical" — exactly what you'd guess a fair split should look like.
- Provably matches the full permutation average
For a linear model specifically, this closed form is provably the same answer the full permutation average from the pizza chapter would have given.
Drag the size slider. Only size's own bar moves — every other feature's SHAP value is untouched, because in a linear model each feature's contribution genuinely doesn't depend on any other feature's value. Watch the total, though: baseline plus every bar summed still always equals the exact prediction, at any size you drag to.
Baseline (a typical house): size , age , distance , not renovated — predicting . This house: size , age , distance , renovated — predicting :
- Size's contribution
— five units above baseline, each worth .
- Age and distance's contributions
- Age: — younger than baseline, and age's weight is negative, so a below-baseline age adds value.
- Distance: , the same logic.
- Renovated's contribution, and the total
Renovated: . All four sum to , and — exactly the predicted price, with no approximation anywhere.
Drag size until its own SHAP contribution reaches at least 90.
This exact shortcut only exists because the model is linear — the moment there's any interaction between features (a tree split, a neural network's nonlinearity), the shortcut breaks and real SHAP implementations fall back to smart sampling strategies that approximate the permutation average without ever computing all of them. The takeaway carries over regardless: SHAP is Chapter 5's fair-credit idea, engineered to actually run on models with more than three features. The next chapter asks a different kind of question about the same prediction: not "how much did each feature contribute," but "what's the smallest change that would have flipped the answer?"