Simple Algorithm
Machine Learning · Convergence · 28 min

Interpretability: SHAP, LIME & Their Limits

Explaining predictions, and how explanations can mislead.

Feature attributions appear in medical papers, credit decisions and every debugging session. They rest on an elegant theorem from cooperative game theory, and on choices the theorem does not make for you. This lesson derives the Shapley value and its uniqueness, shows exactly what SHAP, LIME, partial dependence and integrated gradients compute, and then collects the results that show where explanations fail: equally accurate models with different explanations, explainers that can be fooled, saliency maps that ignore the model, and a theorem that complete, linear attributions can fail to beat random guessing.

What you’ll learn

  • Distinguish what interpretability can mean, and how explanations can be evaluated.
  • Prove that the Shapley value is the unique attribution satisfying efficiency, symmetry, null player and additivity, and state the weighted regression that KernelSHAP solves.
  • Compare interventional and conditional value functions, LIME, partial dependence, ICE, accumulated local effects and integrated gradients.
  • Explain the Rashomon effect, adversarial fooling of perturbation-based explainers, saliency sanity checks and the impossibility theorems for feature attribution.

What would count as an explanation?

"Interpretable" means different things to different people. Lipton (2018) separated transparency, properties of the model itself (a person can simulate it, each part has a meaning, the training algorithm is understood), from post-hoc explanations, which extract information from a trained model without showing exactly how it works: text, visualizations, local explanations, examples. Doshi-Velez & Kim (2017) argued that interpretability needs rigorous evaluation, and proposed three kinds of evaluation.

EvaluationWho and whatTrade-off
Application-groundeddomain experts doing the real task, such as doctors diagnosing patients with the system's helpmost convincing; expensive and specific
Human-groundedlay participants on simplified tasks, such as predicting the model's output from an explanationcheaper; tests general properties, not the real use
Functionally-groundedno humans: a formal proxy for interpretability, such as sparsity, ideally one already validated with humanscheapest; only as good as the proxy
A recurring lesson of the results below: decide the end task first (debugging, recourse, finding spurious features, auditing for bias) and evaluate the explanation against it.

This lesson concerns local feature attribution: given a model ff, an input x∈Rp\mathbf x\in\R^p and usually a reference distribution or baseline, return a number ϕj\phi_j per feature saying how much feature jj contributed to f(x)f(\mathbf x). The global tools of Feature Importance & Its Pitfalls (permutation importance, model reliance) and the interpretable-by-design models of Optimal & Interpretable Trees answer different questions.

The Shapley value

DerivationProof of uniqueness
  1. v=∑∅≠T⊆NcT uT,cT=∑S⊆T(−1)∣T∣−∣S∣ v(S)v=\sum_{\varnothing\ne T\subseteq N}c_T\,u_T,\qquad c_T=\sum_{S\subseteq T}(-1)^{\abs T-\abs S}\,v(S)

    For nonempty T⊆NT\subseteq N, the unanimity game uT(S)=1{T⊆S}u_T(S)=\mathbf 1\{T\subseteq S\} pays only when all of TT is present. The 2p−12^p-1 unanimity games form a basis of all games: every vv is a combination whose coefficients, the Harsanyi dividends, come from Möbius inversion:

  2. ϕj(c uT)={c/∣T∣,j∈T,0,j∉T.\phi_j(c\,u_T)=\begin{cases}c/\abs T, & j\in T,\\ 0, & j\notin T.\end{cases}

    Fix the game c uTc\,u_T for a real cc. Players outside TT are null, so they get 0. Players inside TT are symmetric, so they share equally. Efficiency says the shares add up to c uT(N)=cc\,u_T(N)=c:

  3. ϕj(v)=∑T∋jcT∣T∣\phi_j(v)=\sum_{T\ni j}\frac{c_T}{\abs T}

    Additivity then determines ϕ\boldsymbol\phi on every game: each dividend is split equally among its members. Any two maps with the four properties agree on a basis, hence everywhere; and the Shapley formula has all four properties (each is easy to check from the random-order form), so it is that map.

Predict before you look

Two features. Knowing neither gives the baseline, v(∅)=0v(\varnothing)=0; knowing only feature 1 adds 10, only feature 2 adds 20, and both together add 50. What is feature 1's Shapley value?

Show the answer

20

Average its marginal contributions over the two orders: first, 10−0=1010-0=10; second, 50−20=3050-20=30; so ϕ1=20\phi_1=20 and likewise ϕ2=(20+40)/2=30\phi_2=(20+40)/2=30, summing to 50. In dividend terms, c{1}=10c_{\{1\}}=10, c{2}=20c_{\{2\}}=20 and the interaction c{1,2}=50−10−20=20c_{\{1,2\}}=50-10-20=20 is split equally.

To explain a prediction, make the features players and choose a value function vx(S)v_{\mathbf x}(S), "what the model predicts when only the features in SS are known", minus its value for S=∅S=\varnothing. Efficiency then splits f(x)−Ef(X)f(\mathbf x)-\E f(\mathbf X) among the features: this is SHAP (Lundberg & Lee, 2017). The axioms say nothing about which value function to use, and that choice changes the answers.

Which game? Value functions and KernelSHAP

Three value functions are in common use. Interventional (or marginal): vx(S)=E[f(xS,XSˉ)]v_{\mathbf x}(S)=\E\big[f(\mathbf x_S,\mathbf X_{\bar S})\big], filling in unknown features from their marginal distribution. Conditional: vx(S)=E[f(X)∣XS=xS]v_{\mathbf x}(S)=\E\big[f(\mathbf X)\mid\mathbf X_S=\mathbf x_S\big]. Baseline: vx(S)=f(xS,xSˉ′)v_{\mathbf x}(S)=f(\mathbf x_S,\mathbf x'_{\bar S}) for one reference input x′\mathbf x'. With independent features the first two coincide. With dependent ones they can disagree completely.

DerivationA feature the model never reads
  1. v(∅)=0,v({1})=v({1,2})=x1,v({2})=E[X1∣X2=x2]=ρ x2v(\varnothing)=0,\qquad v(\{1\})=v(\{1,2\})=x_1,\qquad v(\{2\})=\E[X_1\mid X_2=x_2]=\rho\,x_2

    Let (X1,X2)(X_1,X_2) be standard normal with correlation ρ\rho, and let the model read only the first feature, f(x)=x1f(\mathbf x)=x_1. Under the conditional value function, knowing x2x_2 is informative about x1x_1:

  2. ϕ1=12x1+12(x1−ρx2)=x1−12ρx2,ϕ2=12ρx2+12(x1−x1)=12ρx2\phi_1=\tfrac12x_1+\tfrac12\big(x_1-\rho x_2\big)=x_1-\tfrac12\rho x_2,\qquad\phi_2=\tfrac12\rho x_2+\tfrac12(x_1-x_1)=\tfrac12\rho x_2

    Average the marginal contributions over the two orders:

  3. conditional: (ϕ1,ϕ2)=(0.6, 0.4)interventional: (ϕ1,ϕ2)=(1, 0)\text{conditional: }(\phi_1,\phi_2)=(0.6,\ 0.4)\qquad\text{interventional: }(\phi_1,\phi_2)=(1,\ 0)

    At x=(1,1)\mathbf x=(1,1) with ρ=0.8\rho=0.8 the conditional attributions are (0.6, 0.4)(0.6,\,0.4): 40% of the credit goes to a feature the model never touches. The interventional value function gives v({2})=E[X1]=0v(\{2\})=\E[X_1]=0 and hence (1, 0)(1,\,0).

Which is right depends on the question. Interventional values describe the function: a feature the model ignores gets nothing, which is what you want when debugging a model, and Janzing, Minorics & Blöbaum (2020) argue from Pearl's distinction between observing and intervening that dropping a feature should be modeled as an intervention on the model's input. Conditional values describe the information the features carry about the prediction. Sundararajan & Najmi (2020) showed that the many ways of operationalizing the Shapley value give very different attributions, some of them nonzero for features the model never references, so the celebrated uniqueness result does not by itself justify any one of them; they proposed Baseline Shapley (BShap), backed by its own uniqueness result. The interventional choice has a price: it evaluates ff on combinations such as a high income paired with a student's age that may never occur in data, where the model is unconstrained, a weakness exploited below. Kumar, Venkatasubramanian, Scheidegger & Friedler (2020) argue more broadly that the remedies for the mathematical problems of Shapley-based importance bring in further complexity, such as the need for causal reasoning.

Other lenses: LIME, effect plots and gradients

LIME (Ribeiro, Singh & Guestrin, 2016) explains ff near x\mathbf x by an interpretable surrogate:

ξ(x)=arg min⁡g∈G L(f,g,πx)+Ω(g),\xi(\mathbf x)=\argmin_{g\in\mathcal G}\ \mathcal L\big(f,g,\pi_{\mathbf x}\big)+\Omega(g),

where G\mathcal G is a class of simple models (typically sparse linear ones), πx\pi_{\mathbf x} weights perturbed samples by their proximity to x\mathbf x (an exponential kernel of the distance, with a width parameter), and Ω\Omega penalizes complexity. KernelSHAP is this same template with the Shapley kernel, squared loss and no penalty; LIME's heuristic choices do not recover Shapley values and can violate efficiency. In practice LIME's explanations depend on the kernel width and on the random perturbations, so two runs can disagree.

Effect plots describe how the prediction varies with one feature. Partial dependence (Friedman, 2001) averages ff with feature jj set to zz in every example, which evaluates the model off the data whenever features are dependent. Individual conditional expectation curves (Goldstein, Kapelner, Bleich & Pitkin, 2015) show the per-example curves that the average hides. Accumulated local effects (Apley & Zhu, 2020) avoid extrapolation by averaging derivatives over the conditional distribution and integrating:

f~j,ALE(z)=∫zmin⁡zE[∂f(X)∂xj ∣ Xj=t] dt,\tilde f_{j,\mathrm{ALE}}(z)=\int_{z_{\min}}^{z}\E\Big[\frac{\partial f(\mathbf X)}{\partial x_j}\ \Big|\ X_j=t\Big]\,dt,

then centering. For an additive model f=∑kfk(xk)f=\sum_kf_k(x_k) both partial dependence and ALE recover fjf_j up to a constant; they part ways when features are dependent and the model interacts.

Integrated gradients (Sundararajan, Taly & Yan, 2017), for differentiable models, accumulate gradients along the straight path from a baseline x′\mathbf x' to x\mathbf x:

IGj(x)=(xj−xj′)∫01∂f(x′+α(x−x′))∂xj dα,∑jIGj(x)=f(x)−f(x′).\mathrm{IG}_j(\mathbf x)=(x_j-x'_j)\int_0^1\frac{\partial f\big(\mathbf x'+\alpha(\mathbf x-\mathbf x')\big)}{\partial x_j}\,d\alpha,\qquad\sum_j\mathrm{IG}_j(\mathbf x)=f(\mathbf x)-f(\mathbf x').

They satisfy sensitivity (a feature that alone changes the output gets credit, which plain gradients violate at saturation) and implementation invariance (functionally identical networks get identical attributions). Path methods are the only attributions with implementation invariance, a dummy property, linearity and completeness; integrated gradients are the symmetric one among them, the Aumann–Shapley cost-sharing rule of economics.

MethodReference pointCompletenessMain failure
SHAP, interventionalmarginal distribution of absent featuresyesevaluates the model off the data manifold
SHAP, conditionalconditional distributionyescredits features the model never reads; hard to estimate
LIMEperturbations weighted by proximitynounstable; depends on kernel width
Partial dependence / ICEthe data, feature jj overwrittennot applicable (global or per-example curve)extrapolates under dependence
ALElocal conditional derivativesnot applicableneeds enough data per interval; describes effects, not causes
Integrated gradientsa baseline inputyesdepends on the baseline; differentiable models only

How explanations mislead

Many good models, many stories. Breiman (2001) called it the Rashomon effect: a dataset typically admits many models with nearly the same accuracy that differ in which features they use and how, so an explanation of one of them is not an explanation of the data.

Explainers can be fooled. Perturbation-based explainers query the model on synthetic points that differ visibly from real data. Slack, Hilgard, Jia, Singh & Lakkaraju (2020) exploited this with a "scaffolding": a classifier that detects whether an input looks like real data, applies a biased rule (for example, one using race) on real inputs and an innocuous rule on the perturbations. Its predictions on real data stay biased, yet LIME and KernelSHAP report the innocuous feature, as their experiments on datasets including COMPAS showed.

Saliency maps can ignore the model. Adebayo et al. (2018) proposed two sanity checks for saliency methods on images: randomize the model's weights, or retrain it on randomized labels, and see whether the explanation changes. Plain gradients and GradCAM passed; Guided Backpropagation and Guided GradCAM were largely invariant to the parameters of the higher layers, behaving more like edge detectors than explanations of the model.

Attributions can be no better than chance. Bilodeau, Jaques, Koh & Kim (2024) proved that for model classes rich enough to contain piecewise-linear functions, such as ReLU networks, any attribution method that is complete (attributions sum to f(x)f(\mathbf x) minus the baseline average) and linear (an additive model's attributions come from its additive parts), a class that includes SHAP and integrated gradients, can fail to beat random guessing for end tasks such as algorithmic recourse and spotting spurious features. There are uncountably many pairs of models with identical attributions but arbitrarily different local behavior. A positive attribution does not imply that increasing the feature increases the output, and a zero attribution does not imply insensitivity. Simple direct methods, such as evaluating the model repeatedly near x\mathbf x, can do better once the end task is stated.

Key takeaways

  • Interpretability means transparency or post-hoc explanation, and explanations should be evaluated against an end task: application-, human- or functionally-grounded.
  • The Shapley value is the unique attribution with efficiency, symmetry, null player and additivity (proof: unanimity games and Harsanyi dividends); KernelSHAP computes it as weighted least squares with the Shapley kernel.
  • The value function is a modeling choice: interventional values follow the function but query it off the data; conditional values can credit features the model never reads.
  • LIME fits a local surrogate with heuristic weights; partial dependence extrapolates under dependence, ALE does not; integrated gradients are the Aumann–Shapley path attribution, complete and implementation-invariant.
  • Explanations mislead: Rashomon sets of equally accurate models, scaffolds that fool LIME and SHAP, saliency maps that ignore the weights, and complete, linear attributions that can be no better than random guessing for recourse.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which Shapley axiom guarantees that the attributions of a prediction add up to f(x)−Ef(X)f(\mathbf x)-\E f(\mathbf X)?

  1. Symmetry
  2. Efficiency
  3. Null player
  4. Additivity
Show the answer

B. Efficiency

Efficiency says ∑jϕj=v(N)\sum_j\phi_j=v(N), and with vx(S)v_{\mathbf x}(S) measured relative to the baseline, v(N)=f(x)−Ef(X)v(N)=f(\mathbf x)-\E f(\mathbf X). In the SHAP paper this is called local accuracy.

Question 2

A model uses only feature 1, but conditional SHAP assigns substantial credit to feature 2. What is going on?

  1. A bug: Shapley values always give zero to unused features
  2. Feature 2 is correlated with feature 1, and the conditional value function credits the information it carries about the prediction
  3. The model secretly uses feature 2
  4. KernelSHAP sampling noise
Show the answer

B. Feature 2 is correlated with feature 1, and the conditional value function credits the information it carries about the prediction

Under v(S)=E[f(X)∣XS=xS]v(S)=\E[f(\mathbf X)\mid\mathbf X_S=\mathbf x_S], knowing x2x_2 changes the expected prediction through its correlation with x1x_1, so feature 2 is not a null player of this game even though ff ignores it. Interventional values would give it zero.

Question 3

How does KernelSHAP relate to LIME?

  1. They are unrelated: one is game-theoretic, the other a local surrogate
  2. KernelSHAP is LIME with an ℓ1\ell_1 penalty
  3. KernelSHAP is the LIME template with the Shapley kernel, squared loss and no regularization, whose solution is exactly the Shapley values
  4. LIME is a special case of integrated gradients
Show the answer

C. KernelSHAP is the LIME template with the Shapley kernel, squared loss and no regularization, whose solution is exactly the Shapley values

Lundberg & Lee showed that the weighted linear regression of LIME recovers Shapley values for exactly one choice of kernel, loss and penalty. LIME's default heuristic choices do not, which is why its attributions need not sum to the prediction.

Question 4

A complete and linear attribution method assigns a large positive value to feature jj at input x\mathbf x for a ReLU network. What can you conclude about increasing xjx_j slightly?

  1. The output will increase
  2. The output will increase, unless the feature is correlated with another
  3. The output will not decrease
  4. Nothing in general: models with the same attributions can respond in opposite directions
Show the answer

D. Nothing in general: models with the same attributions can respond in opposite directions

Bilodeau et al. (2024) show that for rich model classes such attributions are compatible with arbitrarily different local behavior; completeness ties them to the gap between f(x)f(\mathbf x) and the baseline, which can be dominated by behavior far from x\mathbf x. To learn about small changes of xjx_j, evaluate the model at nearby points or look at the gradient.

Further reading

  • L. S. Shapley, "A value for n-person games," in Contributions to the Theory of Games II, Annals of Mathematics Studies 28, 307–317 (Princeton University Press, 1953).
  • S. M. Lundberg & S.-I. Lee, "A unified approach to interpreting model predictions," Advances in Neural Information Processing Systems 30 (2017).
  • M. T. Ribeiro, S. Singh & C. Guestrin, "'Why should I trust you?': Explaining the predictions of any classifier," Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 1135–1144 (2016).
  • B. Bilodeau, N. Jaques, P. W. Koh & B. Kim, "Impossibility theorems for feature attribution," Proceedings of the National Academy of Sciences 121(2), e2304406120 (2024).
  • C. Rudin, "Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead," Nature Machine Intelligence 1(5), 206–215 (2019).