Inferensys

Glossary

SHAP (SHapley Additive exPlanations)

A game-theoretic framework for explaining the output of any machine learning model by computing the Shapley value for each input feature.
Governance lead reviewing model governance framework on laptop, policy documents visible, executive office setup.
GAME-THEORETIC EXPLAINABILITY

What is SHAP (SHapley Additive exPlanations)?

A unified framework for interpreting model predictions by assigning each feature an importance value for a particular prediction.

SHAP (SHapley Additive exPlanations) is a game-theoretic framework that explains the output of any machine learning model by computing the Shapley value for each input feature. It connects optimal credit allocation from coalitional game theory with local explanations, representing a prediction as a linear sum of additive feature attributions relative to a baseline value.

SHAP unifies six existing interpretability methods under a single theoretical umbrella, satisfying the properties of local accuracy, missingness, and consistency. The framework includes model-agnostic (KernelSHAP) and model-specific (TreeSHAP, DeepSHAP) implementations, providing both global feature importance and instance-level explanations through visualizations like the summary plot and waterfall plot.

AXIOMATIC FOUNDATIONS

Core SHAP Properties

The theoretical guarantees that make SHAP values a uniquely consistent and fair method for feature attribution, rooted in cooperative game theory.

02

Symmetry (Fairness)

The Symmetry property states that if two features contribute identically to every possible subset of other features, they must receive identical SHAP values. This enforces a fundamental fairness constraint: features are judged solely by their impact, not by arbitrary ordering or naming.

  • Core principle: Equal contributions yield equal credit.
  • Game theory origin: Symmetric players in a coalitional game receive the same payoff.
  • Real-world relevance: Prevents bias in explanation where two correlated, equally predictive features might otherwise be arbitrarily ranked.
03

Dummy (Missingness)

The Dummy or Missingness axiom requires that a feature which never changes the model's prediction—regardless of which other features are present—must receive a SHAP value of zero. This prevents spurious importance from being assigned to irrelevant inputs.

  • Zero impact = Zero attribution: A feature with no marginal contribution gets no credit.
  • Handling missing data: In SHAP, a missing feature is represented by its expected value from the background dataset, and its contribution is correctly set to zero.
  • Sanity check: If a random noise column receives a non-zero SHAP value, the explanation method is broken.
04

Additivity (Model Ensembles)

The Additivity property states that for a model ensemble (e.g., a Random Forest or a voting classifier), the SHAP value of a feature is the weighted average of its SHAP values from each constituent model. This allows explanations to be cleanly aggregated.

  • Ensemble transparency: The global explanation is a mathematically sound combination of sub-model explanations.
  • Use case: When auditing a stacked model, you can decompose the final attribution to understand which base learner drove a specific feature's importance.
  • Contrast: Many other attribution methods break down or require re-computation when applied to ensembles.
05

Consistency (Monotonicity)

The Consistency property guarantees that if a model is retrained or modified so that a specific feature's marginal contribution increases (or stays the same) for all subsets, that feature's SHAP value will not decrease. This ensures stability and logical monotonicity in explanations.

  • Model evolution: As models are updated, feature importance shifts are logically consistent.
  • Trust: A feature that becomes strictly more important in a new model version will never be assigned a lower attribution.
  • Unique solution: SHAP is the only additive feature attribution method that satisfies Efficiency, Symmetry, Dummy, and Consistency simultaneously.
SHAP EXPLAINABILITY

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the SHAP framework for interpreting machine learning model predictions.

SHAP (SHapley Additive exPlanations) is a game-theoretic framework for explaining the output of any machine learning model by computing the Shapley value for each input feature. It works by treating each feature as a 'player' in a cooperative game where the 'payout' is the model's prediction. For a specific prediction, SHAP calculates the marginal contribution of a feature by comparing the model's output with and without that feature, averaged over all possible subsets of other features. This process, formalized by the Shapley axioms of efficiency, symmetry, dummy, and additivity, guarantees a unique, fair distribution of credit. The result is an additive feature attribution model where the sum of all feature SHAP values plus a baseline value (the expected model output) exactly equals the model's prediction for that instance.

ALGORITHMIC IMPLEMENTATIONS

Key SHAP Variants

While the Shapley value provides the theoretical backbone, practical deployment relies on specialized algorithms optimized for different model types and computational constraints.

01

KernelSHAP

A model-agnostic implementation that treats the explanation as a weighted linear regression problem. It uses a specially designed Shapley kernel to approximate Shapley values without exhaustive computation over the power set.

  • Mechanism: Samples coalitions, fits a local linear model where weights are determined by coalition size.
  • Key Insight: The kernel ensures the linear model satisfies the efficiency property at the instance being explained.
  • Trade-off: Computationally expensive for high-dimensional data due to sampling requirements.
Model-Agnostic
Compatibility
02

TreeSHAP

A model-specific algorithm that computes exact Shapley values for tree-based models in polynomial time (O(TLD^2) where T is trees, L is leaves, D is depth). It exploits the internal structure of decision trees to track feature splits directly.

  • Advantage: Orders of magnitude faster than KernelSHAP for XGBoost, LightGBM, and random forests.
  • Output: Provides both conditional expectation (observational) and interventional SHAP values.
  • Interaction Values: Natively computes pairwise SHAP interaction values without additional sampling.
Exact
Computation
03

DeepSHAP

A high-speed approximation for deep learning models that combines DeepLIFT rules with Shapley value calculations. It uses a compositional approximation where the SHAP values of network components are combined to approximate the full model's attributions.

  • Mechanism: Propagates attributions layer-by-layer using linear composition rules.
  • Baseline: Requires a carefully chosen background dataset representing missing feature information.
  • Limitation: The approximation quality degrades for highly non-linear activation functions and complex skip connections.
Approximate
Computation
04

Interventional SHAP

A causal interpretation of SHAP that breaks feature correlations by sampling from the marginal distribution. It answers: 'How does the model behave if we actively intervene on this feature?'

  • Method: Replaces feature values with random draws from the background dataset, ignoring dependencies.
  • Use Case: Essential for fairness auditing and scenarios where causal reasoning is required.
  • Contrast: Unlike observational SHAP, it evaluates the model on data points that may lie off the natural data manifold.
Causal
Interpretation
05

Observational SHAP

A formulation that preserves feature correlations by conditioning on observed values. It estimates missing features using the conditional expectation given the known features, reflecting the model's behavior on the natural data manifold.

  • Method: Uses a separate model or non-parametric estimator to impute missing features based on observed ones.
  • Use Case: Preferred when explaining predictions on realistic, correlated data where interventions would create implausible feature combinations.
  • Challenge: Requires accurate estimation of the conditional distribution, which is computationally intensive.
Observational
Interpretation
06

Causal SHAP

An extension that incorporates a causal graph (directed acyclic graph) to compute feature attributions respecting the underlying causal structure of the data. It decomposes the total effect into direct and indirect causal pathways.

  • Mechanism: Uses Pearl's do-calculus to simulate interventions along causal edges.
  • Output: Distinguishes between direct causal effects and spurious associations driven by confounders.
  • Application: Critical for policy evaluation and medical treatment effect analysis where causal reasoning is paramount.
Causal Graph
Requirement
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.