Amortized Linear-time Exact Shapley Value for Product-Kernel Methods

Majid Mohammadi, Siu Lun Chau, Krikamol Muandet

TL;DR

Computing exact Shapley values for machine learning models is notoriously slow, usually forcing practitioners to rely on noisy approximations. This paper introduces PKeX-Shapley, an algorithm that exploits the mathematical structure of product kernels to calculate exact Shapley values in quadratic time ($O(d^2n)$)—achieving an amortized linear-time cost per feature. Crucially, the method requires zero sampling or density estimation and extends beyond standard predictions to explain complex statistical metrics like MMD and HSIC.

What Problem Does This Paper Address?

Shapley values offer a mathematically rigorous way to explain machine learning models by fairly distributing credit (or blame) among input features. However, calculating them exactly requires evaluating a model's output across all $2^d$ possible feature subsets, where $d$ is the number of features. This exponential bottleneck makes exact computation impossible for more than a couple dozen features.

Existing workarounds rely on approximations like Monte Carlo sampling or regression-based estimators (e.g., Kernel SHAP). Unfortunately, these approximations introduce estimation errors that grow aggressively with higher dimensions. While model-specific solutions like TreeSHAP exist for decision trees, kernel methods—despite their widespread use in high-stakes statistical inference—have lacked an efficient, exact, and numerically stable Shapley attribution method.

Methods

The authors focus on product-kernel methods (such as models using RBF, Laplacian, or Automatic Relevance Determination kernels). They leverage two key innovations to break the exponential bottleneck:

  1. Neutral-Factor Removal Operator: Instead of simulating a feature's absence by sampling from a background distribution (which is computationally expensive and introduces data dependencies), they replace the absent feature's kernel factor with its multiplicative identity, $k_j \mapsto 1$. This yields a clean, parameter-free value function that requires no background data.
  2. Prefix-Suffix ESP Recursion: The value function's multiplicative structure allows the authors to express the Shapley formula using Elementary Symmetric Polynomials (ESPs) via Newton's identities. To compute all $d$ feature attributions efficiently without redundant calculations, they split the feature vectors into a "prefix" and a "suffix." This dynamic programming approach allows them to reuse intermediate quantities, bringing the total complexity down to $O(d^2n)$ time and memory for all features combined.

Datasets

The method was evaluated using:

  • Synthetic Datasets: Regression tasks with dimensions scaling from $d=10$ up to $d=1000$ to test scalability and numerical stability.
  • UCI Diabetes Dataset: Used to validate the method's ability to explain distribution discrepancies (MMD) between male and female cohorts.
  • Real-world Benchmark Datasets: Seven datasets (sonar, Wisconsin, ionosphere, breast cancer, skillcraft, sml, and parkinson) were used to evaluate HSIC-based feature selection performance.

Key Insights and Ideas

  • Structure is Key: The multiplicative nature of product kernels means that removing a feature is algebraically equivalent to multiplying by one. This structural property completely bypasses the need for background datasets or density estimation.
  • Bypassing Polynomial Division Instability: While other fields use polynomial division (like TreeSHAP variants) to recover leave-one-out polynomials, those methods suffer from severe numerical instability at moderate dimensions ($d \approx 50$). PKeX-Shapley avoids this by relying strictly on element-wise additions and multiplications, remaining stable even at $d = 1000$.
  • Beyond Predictions: The framework isn't just for model predictions; it seamlessly adapts to global statistical discrepancies like Maximum Mean Discrepancy (MMD) and Hilbert-Schmidt Independence Criterion (HSIC), opening up new avenues for interpretable hypothesis testing and feature selection.

Key Results

  • Massive Speedups: As shown in Figure 1, while brute-force exact computation hits a wall at around 20 features, PKeX-Shapley effortlessly scales to 1,000 features.
  • Flawless Numerical Stability: In stability benchmarks against alternative exact methods (like FFT or Chebyshev interpolation), PKeX-Shapley maintained a microscopic absolute error ($10^{-13}$ to $10^{-12}$) across all dimensions up to $d=1000$, whereas the alternatives suffered catastrophic numerical explosions past $d=25$.
  • Superior Feature Selection: When used for feature selection via HSIC attribution, PKeX-Shapley outperformed established baselines like HSICLasso, Mutual Information, and Tree Ensembles on 5 out of 7 real-world datasets.
Figure 1: Execution time vs. number of features (log–log). Brute-force reaches at most 20 features in 20 s; PKeX-Shapley scales to 1,000.

Limitations and Future Work

The primary limitation is that the algorithm is strictly constrained to product kernels. If a model utilizes a non-product kernel (such as an RBF kernel incorporating a Mahalanobis distance with a full covariance matrix), the multiplicative factorization breaks down.

For future work, the authors suggest exploring ways to relax the product-kernel assumption without losing tractability, extending the framework to compute higher-order feature interactions (Shapley interaction indices), and applying these computational shortcuts to accelerate other explainability methods like partial dependence plots and integrated gradients.

Summary updated

BibTeX
@misc{mohammadi2025amortized,
  author = {Majid Mohammadi and Siu Lun Chau and Krikamol Muandet},
  title = {{Amortized Linear-time Exact Shapley Value for Product-Kernel Methods}},
  year = {2025},
  eprint = {2505.16516},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.16516},
}
Figure