Shapley value

Also known as: Shapley values

On this page 7

The Shapley value is a concept from cooperative game theory that assigns each player a fair share of a jointly produced payoff, based on that player’s average marginal contribution across all possible coalitions. In Explainable AI, the players are the input features of a model, the payoff is a single prediction, and Shapley values state how much each feature pushed that prediction above or below a baseline.

Lloyd Shapley introduced the value in 1953, and it became central to machine learning interpretability through the SHAP framework in 2017. Its appeal is theoretical: it is the only attribution method that satisfies a small set of fairness axioms at once, which gives practitioners a principled answer to the question of which features mattered and by how much.

How the Shapley value is calculated

The Shapley value of a feature is the weighted average of its marginal contributions over every subset of the other features. For each subset S, one computes the model output with the feature added and without it; the difference is the marginal contribution, and the weights depend on the size of S.

Formally, for a feature i among n features, the weight of a subset S equals the factorial of |S| times the factorial of (n – |S| – 1), divided by the factorial of n. This weighting is equivalent to averaging over all possible orderings in which features could join the coalition. The table below shows how quickly the exact computation grows.

Number of featuresCoalitions to evaluatePractical status
532Exact and instant
101,024Exact and fast
20About 1 millionExact but slow
50About 10 to the power 15Approximation required
Growth of exact Shapley computation

Because the number of coalitions is 2 to the power n, exact values are feasible only for small feature sets. Real systems rely on sampling or model-specific algorithms that exploit structure in the model.

The axioms behind Shapley values

The Shapley value is defined by four axioms, and it is the unique allocation that satisfies all of them together. These properties are what make the explanation defensible when stakeholders ask why a model produced a given score.

AxiomGame theory meaningMeaning for a model
EfficiencyShares sum to the total payoffAttributions sum to prediction minus baseline
SymmetryEqual contributors get equal sharesInterchangeable features get equal credit
Dummy (null player)A player adding nothing gets zeroAn unused feature gets zero attribution
AdditivityValues add across combined gamesEnsemble attributions add across members
Shapley axioms and their meaning for model explanations

Efficiency is the property users notice most: a credit score of 640 against an average of 700 might decompose into minus 45 for payment history, minus 25 for utilization and plus 10 for account age, adding up exactly to the gap of minus 60.

Estimation methods in practice

Practical tools estimate Shapley values with approximations tailored to the model type. The choice affects speed, accuracy and the assumptions made about how a feature is removed from the coalition.

MethodModel typeApproachTypical cost
Monte Carlo samplingAny modelAverage over random feature orderingsHigh, tunable by sample count
KernelSHAPAny modelWeighted linear regression on coalitionsHigh for many features
TreeSHAPTree ensemblesExact recursion over tree pathsLow, polynomial time
DeepSHAPNeural networksCombines DeepLIFT rules with SHAPLow, one backward pass
Linear SHAPLinear modelsCoefficient times centered featureNegligible
Main ways to estimate Shapley values

A crucial design choice is the value function: how a missing feature is simulated. Interventional SHAP replaces it with values from a background dataset and explains the model, while observational (conditional) SHAP respects feature correlations and explains the data relationship more closely. The two can give noticeably different answers for correlated inputs.

Shapley values compared with other attribution methods

Shapley values are a local, model-agnostic feature attribution with a global use as well: averaging absolute values across a dataset yields a feature importance ranking. They differ from permutation feature importance, which measures loss in accuracy, and from LIME, which fits a local surrogate without the same axiomatic guarantees.

  • Versus LIME: both fit local models, but Shapley-based KernelSHAP uses weights that guarantee efficiency and symmetry.
  • Versus gradient methods: gradient × input is fast but local to an infinitesimal change, whereas Shapley values consider whole coalitions.
  • Versus permutation importance: permutation scores are global only and can be distorted by correlated features in a different way.

Shapley values also extend beyond single features. Shapley interaction values split an attribution into main effects and pairwise interactions, which complements Friedman’s H-statistic. In training data attribution, the related idea of Data Shapley assigns credit to individual training examples instead of inputs, although its cost is far higher because each coalition requires retraining or a close approximation of it.

For global analysis, practitioners usually inspect summary and dependence plots built from many local explanations. A summary plot ranks features by mean absolute attribution, while a dependence plot shows how one feature’s attribution changes across its range, revealing nonlinear effects and thresholds that a single importance score would hide.

Limitations and common misreadings

Shapley values explain the model, not the world. A large attribution means the model relied on a feature for this prediction, not that changing the feature would change the real outcome; causal conclusions require causal methods.

Results also depend on the baseline or background distribution. Explaining a loan decision against all applicants differs from explaining it against approved applicants only. Correlated features split credit in ways that may look arbitrary, and approximation noise can reorder features with similar values.

Finally, Shapley explanations can be manipulated by adversarial model design, where a biased model hides a sensitive feature behind proxies. Auditors should therefore pair them with faithfulness tests and data-level analysis rather than treat them as proof of fairness.

The short version

Imagine three friends who share a taxi and must split the fare fairly. Each person joins at a different point. The fair share looks at how much each one adds to the cost, averaged over every order in which they could have joined.

Shapley values do the same for a model. The features are the friends. The prediction is the fare. Each feature receives its fair share of the result, and all shares add up to the whole. This makes it easy to see which inputs drove a single decision.

Where it makes a difference

A regional bank uses a gradient-boosted tree model to score small-business loan applications. Regulators require the bank to give specific reasons for every adverse decision, and the old practice of listing the model’s global top features did not reflect individual cases.

The data science team added TreeSHAP to the scoring service, which computes exact Shapley values for about 60 features in a few milliseconds per application. For a declined applicant scoring 0.31 against a baseline approval probability of 0.58, the explanation showed minus 0.14 from recent missed payments, minus 0.08 from a high debt-to-income ratio and smaller effects from other inputs.

Loan officers now receive the three largest negative contributions with each decision, and these drive the reason codes in the decline letter. During a model audit, the same attributions revealed that a postal code feature carried unexpected weight, and the team removed it before the next release.