KernelSHAP: Local Feature Attribution
- KernelSHAP is a model-agnostic framework that leverages weighted least-squares regression to approximate Shapley values, ensuring fair feature attributions.
- It unifies cooperative game theory with local surrogate modeling to interpret diverse black-box models in tabular, time series, and high-dimensional data.
- Recent advances enhance computational efficiency and stability through improved sampling, deterministic weighting, and interaction-aware surrogate extensions.
KernelSHAP is a model-agnostic, sampling-based framework for local feature attribution, originally formulated as a statistically justified, weighted least-squares approximation to the Shapley value from cooperative game theory. It is widely adopted for interpreting the predictions of black-box models (such as deep neural networks, ensembles, and autoencoders) and has become foundational in explainable AI (XAI), specifically for feature importance estimation in tabular, time series, and high-dimensional data domains. Methodologically, KernelSHAP unifies the Shapley attribution principle with local surrogate modeling ideas and is extensible to distributed, privacy-preserving, and interaction-aware settings.
1. Mathematical Foundations and Algorithm
KernelSHAP is built on the Shapley value, which provides a fair allocation of the total “payout” (e.g., a model's prediction) among features by averaging their marginal contributions across all possible feature subsets. For and instance , the exact Shapley value for feature is
where is the expected model output when only is “present” (i.e., fixed, replaced with background). This satisfies efficiency (), symmetry, dummy, and linearity axioms.
Direct computation is intractable for moderate due to the subset enumeration. KernelSHAP circumvents this by fitting a local linear surrogate model on a limited number of sampled “coalitions” , with
and optimizes the weighted squared error
subject to the Shapley constraints (e.g., ). The kernel weight
ensures the estimator obeys the Shapley axioms in expectation. In implementation, coalitions are sampled according to the kernel, perturbed inputs are generated by mixing and a background distribution , model outputs are evaluated, and a weighted linear regression yields the local attributions (Roshan et al., 2023, Remman et al., 2021, Bogdanova et al., 2022, Covert et al., 2020).
Pseudocode Overview
- Input: model , instance , background , samples.
- Compute .
- For : sample , build , evaluate , weight with .
- Solve weighted least-squares for , under Shapley constraints.
- Output local attributions.
2. Practical Implementation, Sampling, and Variants
KernelSHAP's core is a kernel-weighted regression, but practical implementation details have strong implications for speed, variance, and reliability. A primary computational challenge is the number and selection of coalitions:
- Sampling with replacement (standard): Draw coalitions from the kernel and proceed as above. Stochasticity induces variance in attributions.
- Paired/antithetic sampling: For each sampled , include its complement; this halves estimator variance and yields results equivalent to a degree-2 polynomial fit (Covert et al., 2020, Fumagalli et al., 26 Jan 2026).
- Improved weighting/deterministic schemes: Replacing stochastic weights (arising from Monte Carlo frequencies) with deterministic, expectation-matched weights—such as C-kernel or CEL-kernel—reduces variance by up to 50%. Weighting corrections based on Wallenius’ distribution and finite-population inclusion probabilities further improve the estimator’s stability and efficiency (Olsen et al., 2024, Aanes, 13 Jan 2026, Covert et al., 2020).
Table: Key Sampling/Weighting Variants
| Variant | Main Effect | Source |
|---|---|---|
| With replacement | Baseline, introduces variance | (Covert et al., 2020) |
| Paired sampling | Lowers variance, leverages symmetry | (Covert et al., 2020, Fumagalli et al., 26 Jan 2026) |
| C/CEL-kernel | Deterministic weights, variance reduction | (Olsen et al., 2024) |
| Wallenius alloc. | Without replacement, lower variance | (Aanes, 13 Jan 2026) |
Practical choices (e.g., sampling granularity, budget size) directly affect runtime. For , is typically –. Computational complexity is for the regression, with model evaluation cost usually dominating (Chen et al., 5 Jun 2025, Olsen et al., 2024).
3. Theoretical Guarantees and Statistical Properties
The linear regression perspective yields non-asymptotic guarantees. The main result states that, with samples, the estimated attributions obey with probability (Chen et al., 5 Jun 2025).
- Unbiasedness: Many variants (e.g., unbiased KernelSHAP) guarantee , but the original (ordinary linear regression) form achieves lower variance at the expense of negligible bias.
- Variance estimation: Bootstrap schemes—most notably paired bootstrap, the doubled half bootstrap, and the new Symmetric bootstrap—enable finite-sample confidence intervals (Covert et al., 2020, Aanes, 13 Jan 2026).
- Sample complexity tradeoffs: KernelSHAP with leverage-score sampling can, in the worst case, remove a factor versus kernel-weight sampling, though kernel-weighting can be optimal for certain value functions (Chen et al., 5 Jun 2025).
- Efficiency in distributed and privacy-preserving settings is established by modified background/reference selection and orchestration of coalition evaluation (Bogdanova et al., 2022).
4. Limitations, Extensions, and Alternative Weighting Schemes
Despite its generality, KernelSHAP exhibits several limitations and motivates recent extensions:
- Marginal vs. causal attribution: By independently sampling absent features, KernelSHAP captures only direct/marginal effects, neglecting inter-feature causal chains. In domains with substantial feature dependence (e.g., robotic control), this can misestimate true attributions (Remman et al., 2021).
- Sampling-induced instability: Stochastic coalition selection introduces run-to-run variation in explanations. Deterministic sampling over full layers or layer-specific coalitions (e.g., ST-SHAP, layer-1 only) eliminates or sharply reduces instability with little fidelity loss (Kelodjou et al., 2023).
- Support mismatch: Standard KernelSHAP may ascribe low importance to genuinely functionally critical features if is adversarially defined outside the data support. KernelSHAP over the extended support (sampling from the product of marginal distributions) guarantees that small aggregate attributions imply safe feature removal (Bhattacharjee et al., 29 Mar 2025).
- Polynomial and interaction-aware surrogates: PolySHAP extends the linear surrogate to degree- polynomials, capturing non-linear and interaction effects, and is theoretically equivalent to paired sampling for (Fumagalli et al., 26 Jan 2026). KernelSHAP-IQ generalizes to explicit interaction index estimation within the weighted least-squares framework (Fumagalli et al., 2024).
5. Applications and Empirical Impact
KernelSHAP has seen adoption in a broad range of scientific and industrial tasks:
- Model interpretation and debugging: Post-hoc feature attribution for black-box models in health, finance, and security (Roshan et al., 2023, Ho et al., 2019).
- Unsupervised feature selection: In network anomaly detection, ranking features by mean and retraining on the top-ranked subset led to substantial gains in accuracy (0.71→0.90) and score (0.53→0.76) without using labels (Roshan et al., 2023).
- Distributed/explainable data collaboration: DC-SHAP yields consistent, privacy-preserving explanations across horizontal/vertical partitions and reduces RMSE between users by or more (Bogdanova et al., 2022).
- Time-series and sequential data: By flattening sequential inputs and supporting time-consistent attributions, KernelSHAP enables event detection and population-level feature aggregation over RNNs/LSTMs and classical models (Villani et al., 2022, Ho et al., 2019).
- Efficient PAC top- identification: Sampling and stopping condition improvements in KernelSHAP@k achieve up to reductions in sample and runtime in identifying the most-influential features for critical applications (Kariyappa et al., 2023).
- Benchmarking: KernelSHAP consistently outperforms model-agnostic alternatives in high-dimensional faithfulness and error metrics; deterministic and paired-weight variants further improve sample efficiency (Chen et al., 5 Jun 2025, Olsen et al., 2024).
6. Computational Considerations and Open Problems
KernelSHAP's bottleneck is the cost of model evaluations over perturbed inputs, which dominates the regression and sampling overheads. Performance is sensitive to:
- Number of features and background samples .
- Number and method of coalition samplings .
- Bias/variance tradeoffs in weight assignment and sampling regimes.
- Stability requirements and computational budgets in practical deployments.
Recent empirical studies suggest deterministic weighting (paired C-kernel or CEL-kernel) and sampling without replacement (Wallenius allocation) yield $20$– runtime reductions at fixed error, with only negligible additional implementation complexity over standard KernelSHAP (Olsen et al., 2024, Aanes, 13 Jan 2026). However, scaling to or explaining models with highly structured or dependent features (e.g., images, text, graphs) remains a challenge. Theoretical optimality proofs for weighting/correction schemes and further adaptation to dependence-sensitive or causal objectives are active research areas.
7. Summary Table: Core Features and Advances
| Aspect | Baseline KernelSHAP | Recent Advances | Key References |
|---|---|---|---|
| Surrogate Fit | Weighted linear | Polynomial (PolySHAP), interaction | (Fumagalli et al., 26 Jan 2026, Fumagalli et al., 2024) |
| Coalition Sampling | With replacement | Without replacement (Wallenius) | (Aanes, 13 Jan 2026) |
| Weighting | Stochastic (kernel) | Deterministic (C/CEL-kernel) | (Olsen et al., 2024) |
| Variance Estimation | Bootstrap (CLT) | Symmetric/doubled half bootstrap | (Aanes, 13 Jan 2026, Covert et al., 2020) |
| Causality-support | Marginal only | CausalSHAP, extended support | (Remman et al., 2021, Bhattacharjee et al., 29 Mar 2025) |
| Stability | Stochastic neighbors | Layerwise determinism (ST-SHAP) | (Kelodjou et al., 2023) |
| Efficient -Selection | Brute force | Bandit/early stopping (SHAP@k) | (Kariyappa et al., 2023) |
KernelSHAP is thus established as a theoretically sound, empirically validated, and highly extensible framework for local feature attribution and XAI. Continuing research is focused on optimizing computational efficiency, stability, variance control, and faithfulness to underlying data and causal structure.