Inferensys

Glossary

Shapley Additive Explanations (SHAP)

A game-theoretic approach to model interpretability that assigns each feature an importance value for a particular prediction, quantifying the contribution of each clinical variable.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
MODEL INTERPRETABILITY

What is Shapley Additive Explanations (SHAP)?

A game-theoretic framework for explaining the output of any machine learning model by computing the marginal contribution of each feature to a specific prediction.

Shapley Additive Explanations (SHAP) is a unified framework for interpreting model predictions by assigning each input feature an importance value, called a SHAP value, for a particular prediction. It is based on Shapley values from cooperative game theory, which fairly distribute the payout of a cooperative game among its players. In the machine learning context, the game is the prediction task, the players are the input features, and the payout is the difference between the model's actual prediction and the average prediction. SHAP values quantify the additive contribution of each feature, ensuring that the sum of all feature contributions equals the final prediction offset from the baseline.

SHAP overcomes the inconsistency of earlier feature attribution methods by satisfying three desirable properties: local accuracy, missingness, and consistency. Local accuracy guarantees that the explanation model matches the original model's output for the specific input. Missingness ensures that a missing feature receives zero attribution. Consistency states that if a model changes so a feature's contribution increases or stays the same, its SHAP value should not decrease. Implementations like Kernel SHAP and Tree SHAP provide model-agnostic and model-specific approximations, respectively, enabling the explanation of complex clinical models, such as a sepsis predictor, by revealing which physiological variables most influenced a risk score.

Axiomatic Foundations

Key Properties of SHAP

SHAP values are not arbitrary feature importance scores; they are the unique solution that satisfies three fundamental axioms from cooperative game theory, ensuring consistency and fairness in model interpretability.

01

Local Accuracy (Efficiency)

The sum of all SHAP values for a prediction equals the difference between the model's output for that instance and the average model output. This guarantees additive feature attribution.

  • Mechanism: If the base value (expected prediction) is $E[f(x)]$ and the actual prediction is $f(x)$, the sum of all $\phi_i$ must equal $f(x) - E[f(x)]$.
  • Clinical Relevance: For a sepsis predictor, this ensures the total risk score is completely decomposed into contributions from heart rate, temperature, and lab values with no unexplained variance.
∑ φᵢ = f(x) - E[f(x)]
Core Identity
02

Missingness

A feature that is not present in the model input must be assigned a SHAP value of exactly zero. This axiom ensures that absent features do not distort the explanation.

  • Implementation: Missing features are handled by integrating them out using a background dataset, effectively replacing them with expected values.
  • Practical Impact: When a lab test is not ordered for a patient, its SHAP value is zero, preventing the model from fabricating influence from unobserved clinical variables.
03

Consistency (Monotonicity)

If a model changes so that a feature's marginal contribution increases or stays the same regardless of other features, its SHAP value cannot decrease. This rewards truly influential features.

  • Formal Definition: For any two models $f$ and $f'$, if $f'_x(S \cup {i}) - f'_x(S) \geq f_x(S \cup {i}) - f_x(S)$ for all subsets $S$, then $\phi_i(f', x) \geq \phi_i(f, x)$.
  • Why It Matters: This prevents a scenario where a feature becomes more important to the model but its attribution score paradoxically drops, a flaw present in earlier methods like LIME.
04

Shapley Value Uniqueness

SHAP is the only feature attribution method that simultaneously satisfies Local Accuracy, Missingness, and Consistency. This game-theoretic foundation provides a legally defensible audit trail.

  • Cooperative Game Theory Origin: Derived from Lloyd Shapley's 1953 solution for fairly distributing payouts among players in a coalition based on their marginal contributions.
  • Clinical Governance: For regulatory submissions under the EU AI Act, SHAP's axiomatic guarantees provide mathematical rigor that heuristic attribution methods cannot match.
05

Kernel SHAP Approximation

Computing exact SHAP values requires evaluating $2^M$ feature coalitions, which is computationally intractable. Kernel SHAP uses a weighted linear regression to approximate these values efficiently.

  • Approach: It samples coalitions and solves a least-squares problem with a Shapley kernel weighting function that prioritizes coalitions with few or many features.
  • Trade-off: While faster than exact computation, Kernel SHAP remains model-agnostic and can be applied to any black-box model, including ensemble methods and deep neural networks.
06

Tree SHAP Optimization

For tree-based models like XGBoost, LightGBM, and random forests, Tree SHAP computes exact SHAP values in polynomial time by exploiting the internal structure of decision trees.

  • Performance: Reduces complexity from $O(TL2^M)$ to $O(TLD^2)$, where $T$ is trees, $L$ is leaves, and $D$ is tree depth.
  • Clinical Deployment: Enables real-time feature attribution for gradient-boosted early warning scores without sampling error, critical for time-sensitive sepsis prediction.
MODEL INTERPRETABILITY

Frequently Asked Questions

Clear, technical answers to the most common questions about applying Shapley Additive Explanations to clinical decision support systems.

SHAP (SHapley Additive exPlanations) is a game-theoretic framework for interpreting the output of any machine learning model by assigning each input feature an importance value for a specific prediction. It works by computing Shapley values, a concept from cooperative game theory, which fairly distributes the prediction outcome among the features. For a clinical prediction—such as a sepsis risk score—SHAP quantifies exactly how much each variable (e.g., lactate level, heart rate, WBC count) pushed the prediction away from the baseline average. The method considers all possible feature coalitions, evaluating the model's output with and without each feature to measure its marginal contribution. The result is an additive explanation where the sum of all SHAP values equals the difference between the model's actual prediction and the expected prediction. This property, known as local accuracy, ensures mathematical consistency and makes SHAP particularly valuable for auditing high-stakes clinical models where understanding the "why" behind a recommendation is as critical as the recommendation itself.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.