LinearSHAP and Exact Computation
You'll learn when SHAP values can be computed exactly for linear models and why this matters for interpretation speed and accuracy.
The Core Idea
For linear models (linear regression, logistic regression), we don't need approximation algorithms like KernelSHAP or sampling methods. The mathematical structure of linear models allows us to compute SHAP values in closed form—directly from the model's coefficients and feature values.
In a linear model, the prediction is simply: prediction = w₀ + w₁x₁ + w₂x₂ + ... + wₙxₙ, where w are weights and x are features.
Why LinearSHAP Works Exactly
The Shapley value framework requires calculating a feature's marginal contribution across all possible feature coalitions. For linear models, this simplifies dramatically because contributions are additive and independent.
The SHAP value for feature i in a linear model is:
SHAP_i = w_i × (x_i - x̄_i)
Where w_i is the coefficient and x̄_i is the background dataset mean for that feature. This formula captures exactly how much feature i shifts the prediction from the baseline (mean prediction).
The Practical Advantage
Think of it like calculating a restaurant bill split: if everyone ordered independently-priced items, you can compute each person's share instantly. But if people shared dishes (feature interactions), you'd need complex calculations. Linear models are the "independent items" case—no approximation needed, instant and exact.
Key Takeaway: LinearSHAP computes exact SHAP values for linear models using a closed-form solution based on coefficients and feature deviations from their means, making it computationally efficient and perfectly accurate without any sampling or approximation.