liveBook · Manning

SHAP

As explained in Ensemble Methods for Machine Learning

SHAP is a model-agnostic explainability technique that attributes an individual model prediction to its input features using Shapley values.

SHAP (SHapley Additive exPlanations) explains one prediction by assigning part of its value to each input feature. It is a model-agnostic, local explainability method: rather than describing a model’s behavior everywhere, it asks why this particular example received this prediction. A feature’s attribution reflects how much it contributes relative to a baseline prediction. section 9.4.2 section 9.0

Its intuition comes from cooperative game theory. If a team earns a prize, each person’s fair share should account for what they add to every possible group they could join. SHAP treats features as team members and the prediction as the prize: a Shapley value averages a feature’s added contribution across feature coalitions. The resulting attributions divide the prediction’s change from its base value among the features. section 9.4.2 section 9.6

Figure 9.17 Computing the Shapley values for Dev. The top row is all the coalitions with Dev. The middle row shows the corresponding coalitions without Dev. The last row shows the individual weighted differences in the values of the coalitions. Summing across the last row gives us the Shapley values for Dev: φDev = 6.
CH09_F17_Kunapuli

Compare each coalition with and without Dev, weight the change in coalition value, and sum those changes to obtain one Shapley value. The same accounting is used to assign a prediction’s feature attributions. section 9.4.2

A practical SHAP explanation follows this pattern:

  • Choose the individual prediction to explain and a base or average prediction for comparison. section 9.4.2 section 9.4.2
  • Measure each feature’s contribution across possible feature combinations rather than crediting it from only one ordering. section 9.4.2
  • Assign positive values to features that push the prediction above the base value and negative values to those that push it downward. section 9.4.2
  • Check that the feature contributions add to the explained prediction; this additivity also supports aggregation in ensembles. section 9.6

Explaining an XGBoost prediction

A TreeSHAP explainer can evaluate one held-out XGBoost example and return its feature attributions. A waterfall plot pairs the example’s feature values with their Shapley values. A force plot instead shows the prediction moving from the average value of -0.194 to 0.52: right-pointing features raise it, while left-pointing features pull it back toward the base value. section 9.4.2 section 9.4.2 section 9.4.2

Direct Shapley-value computation becomes infeasible for real-world data with many features and examples because it considers all feature combinations. SHAP uses a local surrogate approach to approximate these values, while TreeSHAP is a specialized variant for tree-based models. SHAP and LIME both explain local predictions, but SHAP bases feature credit on Shapley values; neither method is fundamentally designed to evaluate feature interactions. section 9.6 section 9.6 section 9.6

How Ensemble Methods for Machine Learning covers it

How deep it goes
Derives feature credit from Shapley coalitions, then addresses practical approximation and efficient tree-based computation.
Examples
Uses a four-person Kaggle prize coalition and TreeSHAP explanations of an XGBoost test example with waterfall and force plots.
What it assumes
Assumes familiarity with machine-learning predictions and feature importance, then introduces Shapley values through a coalition analogy.
What you can do after
Apply it via TreeSHAP and visualization plots to interpret an individual XGBoost prediction.
How it connects
Connects local interpretability with Shapley values, LIME, local surrogate models, TreeSHAP, and feature interactions.

Also explained in

Compare how 5 books explain SHAP →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Ensemble Methods for Machine Learning. The section links point to the parts of the book it draws on.