- Introduced by
- Lundberg, S.M. & Lee, S.-I.
- Year
- 2017
- Type
- Model-explanation method (Shapley-value attribution)
What does it do?
SHAP (SHapley Additive exPlanations) is a model-explanation method introduced by Scott Lundberg and Su-In Lee in 2017.
It uses Shapley values from cooperative game theory to measure how much each input feature contributes to a prediction from a trained machine-learning model, which makes otherwise opaque models easier to interpret. It supports global explanations (overall feature importance) and local explanations (why one specific prediction came out as it did).
The intuition behind the method
A trained model such as a random forest or a deep network turns a row of features into a prediction, but it does not tell you why. SHAP borrows an idea from game theory: imagine the features are players cooperating to produce the prediction, and ask how the 'payout' — the gap between this prediction and the average prediction — should be fairly divided among them. Each feature's fair share is its SHAP value, so you can read off which features pushed a prediction up and which pulled it down, for a single case or across the whole dataset.
History
SHAP was introduced by Scott Lundberg and Su-In Lee in 2017, in a paper presenting a unified approach to interpreting model predictions that connected several earlier additive explanation methods under Shapley-value attribution from cooperative game theory. The same paper introduced KernelSHAP, a model-agnostic estimator. The exact, fast variant for tree ensembles, TreeSHAP, was developed in later work by Lundberg and colleagues rather than in the 2017 paper. SHAP has since been widely used to explain black-box models in many fields.
When to use it
Choose SHAP when you already have a trained model whose predictions need explaining, such as gradient-boosted trees, random forests or neural networks. It applies to many model types, and feature encoding and the choice of background data both affect the results. Use it when the question is which features the model relies on, either overall or for a given case. Do not use it to fit or improve a model, to estimate causal effects, or as a substitute for checking predictive performance. SHAP explains the fitted model, so its reliability depends on that model's predictive performance and on how much data it was trained on; very small training sets give unreliable attributions. When data are this scarce, or when the model is simple enough to read directly, a directly interpretable model such as a decision tree may be the more transparent choice.
Limitations and considerations
- Requires an already-trained model: SHAP explains the function the model has learned, so its explanations can be no better than that model.
- Attributions describe how the model behaves on the data, not the causal effect of a feature in the real world.
- KernelSHAP is an approximation and is slow on large datasets or when there are many features.
- With a small training sample, the underlying model is less reliable, and so are the attributions drawn from it.
- Attributions depend on the background (reference) dataset that defines the baseline and stands in for features that are left out of a prediction; a different reference sample can change the values, so the results are not fully stable.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Attributes each prediction additively: the feature contributions plus the baseline (the average model output) sum exactly to the model's output, so every explanation accounts for the whole prediction.
- Gives both a global ranking of feature importance and local, per-prediction explanations from the same set of values.
- Shapley values come from an established allocation rule in cooperative game theory, which gives the attributions a precise, formal definition.
- TreeSHAP computes exact explanations quickly for tree-based models such as random forest and XGBoost.
- KernelSHAP can be applied to any trained model, at a higher computational cost.
Applications
- Explaining individual predictions of a trained classifier or regressor, for example a risk score, so that case-level contributions can be inspected.
- Ranking global feature importance for a tree ensemble to see which inputs the model depends on most.
- Checking whether a model leans heavily on a sensitive or proxy feature, as a diagnostic; this does not by itself establish fairness.
- Comparing feature contributions across subgroups of the data by computing SHAP values separately on each subset.
How it works
How it works
SHAP rests on a trained black-box model — for example XGBoost, a random forest, or a deep network. The goal is not to refit anything but to explain what that model has already learned, attributing its predictions to the input features.
Each prediction is decomposed additively: it equals a baseline value (the average model output) plus the contributions of all the features. Every feature receives a SHAP value, its share of the difference between this prediction and the baseline, and those shares add up exactly to the prediction.
Formula
f(x) = \phi_0 + \sum_{i=1}^{M} \phi_iThe shares are computed as Shapley values. A feature's Shapley value averages its marginal contribution over all subsets of the other features, weighting each subset by how many feature orderings produce it, so every way of adding features to the prediction counts. The baseline is the expected model output over a background (reference) dataset. TreeSHAP computes these exactly and quickly for tree-based models, while the model-agnostic KernelSHAP works for any model but is slower.
The resulting SHAP values can be read locally — explaining a single prediction by showing which features raised or lowered it — or aggregated across the dataset to give a global ranking of feature importance. Global importance is commonly computed as the mean of absolute SHAP values across rows, because signed averages can cancel out; the signed values show the direction of each feature's effect for individual rows. This turns a black-box model into something a reviewer can inspect.
Common pitfalls
- Reading SHAP values as causal effects rather than as explanations of the model's predictions.
- Explaining a poorly fitted model and trusting its attributions; check predictive performance before interpreting them.
- Using KernelSHAP on large data or many features when TreeSHAP can give exact results for tree-based models much faster.
- Comparing SHAP values across models or datasets without remembering that each value is relative to the baseline (the average model output).
- Ignoring correlated features and interactions: when features are strongly correlated or interact, credit for a prediction can be split between them, so a feature's rank may depend on which correlated partners are included.
- Presenting a single SHAP ranking as stable without a sensitivity check; repeat the analysis with alternative background samples and see whether the ranking holds.
Frequently asked questions
Do I need to retrain my model to use SHAP?
No. SHAP explains a model you have already trained, such as XGBoost, a random forest, or a deep network, by attributing its existing predictions to the input features. It does not refit or change the model.
What is the difference between TreeSHAP and KernelSHAP?
TreeSHAP computes exact SHAP values quickly for tree-based models like random forest and XGBoost. KernelSHAP is model-agnostic and works for any model, but it is an approximation and is considerably slower, especially on large data.
Can SHAP explain a single prediction?
Yes. That is its local mode: for one case it shows how much each feature pushed the prediction above or below the baseline, with the contributions adding up exactly to the prediction. Aggregating these across the dataset gives global feature importance.
How much data do I need?
SHAP itself does not set a sample-size threshold. It explains the fitted model, so a small training set makes both the model and its attributions less reliable. Check predictive performance on held-out data first; if data are very scarce, a directly interpretable model such as a decision tree may be the safer choice.
Related methods
Sources
Lundberg, S.M. & Lee, S.-I. (2017). A Unified Approach to Interpreting Model Predictions. Advances in Neural Information Processing Systems, 30, 4766–4777.
Open publication reference