← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / scientific-agent-skills / skills / shap / references / theory.md

SHAP Theory and Interpretation

SHAP applies Shapley-style credit allocation to model explanations. The numerical result is defined by more than the fitted model: it also depends on the model output, background distribution, masking rule, and any coalition constraints.

Additive Explanation

For one scalar model output and one row x, SHAP constructs an additive decomposition:

f_explained(x) = base_value + sum_i phi_i(x)

For modern tabular shap.Explanation objects:

reconstructed = explanation.base_values + explanation.values.sum(axis=1)

The equation is meaningful only when the output units are known. A raw margin, probability, log loss, and logit are different quantities.

Cooperative-Game Formulation

Let F be the set of features and v(S) the value assigned to coalition S. A Shapley value for feature i is:

phi_i =
  sum over S subset of F \ {i}
  [ |S|! (|F|-|S|-1)! / |F|! ]
  * [v(S union {i}) - v(S)]

This averages the marginal contribution of i over all feature orderings.

In machine learning, defining v(S) is the hard part because a model normally requires all inputs. The masker and background distribution specify how hidden features are integrated or imputed.

What the Axioms Mean

Classic Shapley values satisfy:

The SHAP paper describes related properties for additive feature-attribution methods:

These are mathematical allocation properties. They do not mean:

Avoid calling SHAP values "fair" without specifying that the term refers only to a cooperative-game allocation axiom.

The Value Function Is Part of the Result

Common tabular games include:

Marginal/interventional game

Hidden features are sampled from a background distribution independently of the observed features.

Conceptually:

v(S) = E_background[f(x_S, X_not_S)]

Advantages:

Limitations:

Conditional game

Hidden features are drawn from a distribution conditional on observed features:

v(S) = E[f(X) | X_S = x_S]

Advantages:

Limitations:

Partitioned game

Only coalitions compatible with a hierarchy are considered. The resulting allocations are Owen values.

Advantages:

Limitation: the hierarchy is an assumption and changes the game.

There is no universal answer to "the SHAP value" without specifying the game.

Background and Baseline

The base value is the reference-game expectation, not automatically:

Different backgrounds can change:

Treat background sensitivity as a substantive analysis, not just a runtime check.

Output Scale

SHAP values use the additive scale selected by the explainer.

Examples:

A display transform such as link="logit" on a force plot changes labels, not the computed SHAP game. If probability-space additivity is required for supported trees, configure TreeExplainer(model_output="probability", feature_perturbation="interventional", data=...).

Do not compare mean absolute SHAP magnitudes across models or outputs on different scales.

Local and Global Quantities

Local attribution:

phi_i(x)

Global mean absolute attribution:

E_x[abs(phi_i(x))]

Mean absolute attribution:

Mean signed attribution can cancel heterogeneous effects. Plot the distribution before summarizing.

Exact and Approximate Algorithms

Unconstrained exact Shapley computation grows exponentially with feature count. SHAP uses model-specific algorithms or sampling:

"Exact" always means exact under a specified output, background, masker, and coalition game.

Interaction Values

Tree SHAP can decompose attribution into a symmetric interaction matrix.

For one row:

interaction = explainer.shap_interaction_values(X_eval)

An interaction value describes non-additivity in the fitted model under the chosen game. It does not prove biological, physical, or causal interaction.

Scatter-plot vertical dispersion is only a clue; compute or test interactions before labeling them.

Correlation and Credit Sharing

When two features contain similar information, multiple allocations can be defensible:

Instability across folds, seeds, backgrounds, or equivalent model fits is evidence that individual attribution is not uniquely supported by the problem. Report grouped results or sensitivity rather than selecting one convenient ranking.

SHAP Is Not Causal

SHAP makes predictive relationships visible. A positive attribution does not imply that increasing the feature would increase the real-world outcome.

Confounding, mediation, reverse causality, selection bias, and feature redundancy can all make predictive patterns unsuitable for intervention.

Use causal language only when:

Even then, describe exactly what quantity is attributed.

SHAP Is Not a Fairness Certificate

Attribution can help investigate:

It cannot alone establish:

Protected-feature attribution can be small while proxies drive disparities. Conditional attributions can also assign protected-feature credit even when the model does not directly consume it. Pair SHAP with outcome, error, calibration, threshold, and data-quality analyses.

SHAP Is Not Recourse

A waterfall answers "how this model output is allocated relative to this reference." It does not answer:

Use dedicated counterfactual/recourse methods with feasibility and causal constraints.

Uncertainty and Stability

A standard SHAP plot usually shows point estimates, not uncertainty.

Sources of variation include:

Useful stability analyses:

  1. bootstrap or cross-fit the model;
  2. repeat background sampling;
  3. repeat approximation seeds;
  4. compare rankings and signed distributions;
  5. report intervals or rank stability;
  6. separate model uncertainty from explainer approximation uncertainty.

Comparisons With Other Importance Measures

Permutation importance

Measures predictive performance degradation after shuffling a feature.

Split/gain importance

Summarizes how a tree used features during fitting.

Linear coefficients

Describe change per input unit on the model's linear scale.

Partial dependence

Averages predictions while varying a feature.

These answer different questions. Agreement is reassuring but not proof; disagreement should trigger an assumptions review.

Interpretation Checklist

Before making a claim:

Sources