KernelSHAP: Model-Agnostic Approximation
What You'll Learn
You'll learn how KernelSHAP uses weighted linear regression to efficiently approximate exact SHAP values for any black-box model.
The Challenge with Exact SHAP
Computing exact SHAP values requires evaluating all possible feature coalitions—an exponential problem. For a model with n features, you'd need 2^n evaluations, which becomes computationally infeasible for even moderately complex models.
KernelSHAP's Solution
KernelSHAP treats SHAP value estimation as a weighted linear regression problem. Here's the core idea:
-
Sample coalitions: Instead of evaluating all 2^n possible feature subsets, randomly sample a manageable number of coalitions (e.g., 1,000-5,000)
-
Create binary masks: For each coalition, create a binary vector indicating which features are "present" (1) or "absent" (0)
-
Evaluate predictions: For absent features, replace them with background values (typically from a reference dataset) and get model predictions
-
Apply SHAP kernel weights: Weight each coalition using a special kernel that gives higher importance to coalitions of extreme sizes (very small or very large)—these reveal individual feature contributions most clearly
-
Fit linear model: Regress the model predictions against the binary coalition indicators, using SHAP kernel weights. The learned coefficients approximate the SHAP values
Why It Works Across Any Model
KernelSHAP only requires your model to produce predictions—it doesn't need gradients, tree structures, or any internal architecture details. This makes it truly model-agnostic, working equally well for neural networks, ensembles, or proprietary APIs.
Key Takeaway: KernelSHAP approximates computationally expensive SHAP values through weighted regression on sampled feature coalitions, making Shapley-based explanations practical for any black-box model at the cost of some approximation error.