Inferensys

Glossary

SHAP Interaction Values

An extension of SHAP that captures pairwise feature interaction effects by distributing credit among all pairs of features.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
Pairwise Feature Attribution

What is SHAP Interaction Values?

SHAP Interaction Values extend the standard SHAP framework to capture pairwise feature interaction effects by distributing credit among all pairs of features, not just individual features.

SHAP Interaction Values decompose a model's prediction into contributions from individual features and all pairwise feature interactions, ensuring the sum of all main effects and interaction effects equals the difference between the prediction and the baseline. This is achieved by extending the Shapley value from cooperative game theory to a Shapley-Taylor index, which allocates credit fairly among coalitions of features. The resulting interaction matrix quantifies the synergistic or antagonistic effect between any two features for a specific prediction.

Computationally, exact interaction values require evaluating the model on all subsets of features, which is exponentially expensive. TreeSHAP provides an exact, polynomial-time algorithm for tree-based models by exploiting their internal structure. For other model types, approximations are necessary. A SHAP Dependence Plot visualizes these interactions by coloring points by a second feature, revealing how the relationship between a feature's value and its SHAP value changes depending on the interacting feature's state.

PAIRWISE FEATURE ATTRIBUTION

Key Properties of SHAP Interaction Values

SHAP Interaction Values extend the standard additive SHAP framework by decomposing a model's prediction into main effects and pairwise interaction effects, revealing how features work together to influence outputs.

01

Symmetry of Interactions

The interaction value between feature i and feature j is symmetric, meaning Φ_{i,j} = Φ_{j,i}. This property ensures that the captured interaction effect is a shared, undirected contribution. The total interaction effect is split equally between the two features in the decomposition, preventing double-counting and providing a consistent attribution of the joint effect.

02

Efficiency with Interactions

The sum of all main effects and all pairwise interaction effects exactly equals the difference between the model's prediction f(x) and the baseline value. This extends the standard SHAP efficiency property:

  • Main effects capture independent feature contributions
  • Interaction effects capture the remaining joint contributions
  • The decomposition is exhaustive with no unexplained residual
03

Interaction Detection via Dependence Plots

SHAP dependence plots reveal interactions through vertical dispersion. When a scatter plot of feature value vs. SHAP value shows spread rather than a clean curve, an interaction is present. Coloring points by a second feature's value exposes the interacting variable:

  • Clustered colors indicate strong interaction
  • Vertical spread at fixed x quantifies interaction magnitude
  • Enables discovery of non-linear feature synergies
04

Combinatorial Foundation

Interaction values are computed by considering all coalitions of features that exclude both feature i and feature j. The interaction effect is the marginal contribution of adding the pair together, minus their individual marginal contributions. This requires evaluating the model on 2^(M-2) subsets for M features, making exact computation exponentially expensive and necessitating sampling approximations.

05

Zero Interaction Under Independence

If two features contribute to the model's output completely independently—meaning their joint effect equals the sum of their individual effects—their SHAP interaction value is zero. This property makes interaction values a precise detector of non-additive model behavior, distinguishing between models that treat features independently and those that learn complex feature conjunctions.

06

TreeSHAP Interaction Computation

For tree-based models, TreeSHAP computes exact interaction values in O(TLD^2) time, where T is the number of trees, L is the maximum number of leaves, and D is the maximum tree depth. The algorithm tracks how pairs of features are split across tree paths simultaneously, avoiding the exponential complexity of model-agnostic methods and providing exact, deterministic interaction matrices.

SHAP INTERACTION VALUES

Frequently Asked Questions

Clear, technically precise answers to the most common questions about capturing and interpreting pairwise feature interactions using the SHAP framework.

SHAP interaction values are an extension of the standard SHAP framework that decompose a model's prediction not only into main effects for individual features but also into pairwise interaction effects between features. While a standard SHAP value distributes the prediction credit among N features, SHAP interaction values distribute the credit among all N × N feature pairs, represented as a matrix Φ[i, j]. The diagonal elements Φ[i, i] represent the main effect of feature i, and the off-diagonal elements Φ[i, j] capture the residual interaction effect between feature i and feature j that remains after accounting for their individual main effects. This decomposition is guaranteed by the Shapley-Taylor interaction index, which extends the game-theoretic axioms of efficiency, symmetry, and linearity to interactions. The total prediction is reconstructed as the sum of all matrix elements: f(x) = baseline + Σ_i Σ_j Φ[i, j].

INTERACTION DETECTION COMPARISON

SHAP Interaction Values vs. Other Interaction Methods

Comparing SHAP Interaction Values against alternative methods for detecting and quantifying pairwise feature interactions in machine learning models.

FeatureSHAP Interaction ValuesFriedman's H-StatisticPartial Dependence Interactions

Theoretical Foundation

Game-theoretic Shapley values

Variance decomposition

Partial dependence function differences

Captures Directionality

Model-Agnostic

Handles Correlated Features

Computational Complexity

O(M^2 * 2^M) exact

O(M^2) with sampling

O(M^2) grid evaluations

Provides Instance-Level Interactions

Decomposes Prediction Additively

Visualization Support

Dependence plots, summary plots

Bar charts, heatmaps

2D partial dependence plots

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.