Paper · 2024-10-02 · cs.LG, cs.AI
Provably Accurate Shapley Value Estimation via Leverage Score Sampling
Leverage SHAP estimates Shapley values by weighted least squares over sampled feature subsets, drawn with leverage scores that have a closed form, so no subset list is built. Author-reported: about 50% lower error than the SHAP library's Optimized Kernel SHAP, averaged over 5n to 160n evaluations on eight datasets.
Feature attributionActive learningImportance weightingexplainabilityshapley-valuessamplingregression
arXivPDFCodeMarkdown12 min read
AI-compiled by claude-haiku-5-5 on 2026-10-18, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Shapley values explain a model's prediction by sharing out credit among its input features: each feature gets a number for how much it moved the output. Computing them exactly means asking the model about every combination of features, which grows too fast to be practical as the number of features rises.
Kernel SHAP is the popular shortcut. It asks the model about a sample of feature combinations and solves a regression problem to recover the credit numbers. Which combinations it samples matters a lot, and its sampling rule was a heuristic that had no accuracy guarantee at the time.
This paper swaps that rule for leverage-score sampling, a standard way to pick the most informative rows of a regression. The authors show that the scores for this problem have a simple form, so the sample can be drawn without listing every combination. The result, Leverage SHAP, is a lightweight change to Kernel SHAP that comes with accuracy guarantees. In the authors' experiments it has lower error than the optimized Kernel SHAP in the widely used SHAP library.
TL;DR
Leverage SHAP changes only how Kernel SHAP chooses its feature subsets. It samples them with leverage scores, which have a closed form, and then solves a projected weighted least-squares problem. The paper gives a guarantee on the regression objective, not directly on the Shapley values. Author-reported: about 50% lower error than Optimized Kernel SHAP, averaged over budgets from 5n to 160n evaluations. Not independently re-run.
Problem
Exact Shapley values need one model evaluation per feature subset, so O(2^n) for n features §1.1. Kernel SHAP reduces this by estimating the values from m sampled subsets, with rows weighted by w(|S|) = 1 / (C(n, |S|) · |S| · (n − |S|)) eq. 4. That sampling distribution is a heuristic. When the paper was submitted, no non-asymptotic accuracy guarantee was known for Kernel SHAP with fewer than 2^n − 2 samples §1.2. Noisy value estimates, for example expectations over a random baseline, make the problem harder and are the setting the authors target §1.2.
Method
The method rests on a regression view of Shapley values. Write z for a 0/1 indicator of a feature subset, v(z) for the model's value on that subset, and n for the number of features. The Shapley vector φ is the solution of a least-squares problem over the rows z with 0 < |z| < n, weighted by w(|z|), subject to the constraint that the values sum to v(all) − v(∅) §2, eq. 6–7.
- Remove the constraint. Let P = I − 11ᵀ/n, A = ZP and b = y − Z1 (v(all) − v(∅)) / n. The constrained problem becomes an unconstrained least-squares problem in A and b, and the answer is shifted back by (v(all) − v(∅))/n · 1 §3, eq. 8, eq. 9.
- Leverage scores have a closed form. Because AᵀA = P/n, the leverage score of the row for subset z is 1 / C(n, |z|) §3.1. All subsets of one size share a score, so sampling proportional to leverage gives every size the same total weight. Equivalently, draw a size s uniformly from 1 to n − 1, then a subset of that size uniformly §1.2, fig. 2.
- Pair the samples. Each sampled subset is evaluated together with its complement, because the two have equal leverage and equal kernel weight §3.2. The idealised scheme keeps each pair independently with probability min(1, 2c·ℓ_z), where c is a scale chosen so the expected number of evaluations is m − 2 §3.2, eq. 13. Each kept row is weighted by w(|z|) divided by its inclusion probability alg. 1.
- Sample without replacement, size by size. The sampler needs one binomial or fixed count per size and then a uniform draw of subsets of that size, so it never enumerates the 2^n rows app. J, alg. 2, alg. 3. For even n the middle size is handled separately so that a pair is never drawn twice app. J.
- Solve. Take the weighted least-squares solution of the sampled, projected system. Use the minimum-norm solution, because AᵀA is singular alg. 1 §3.
Algorithm 1 of the paper is the theoretical version. The released estimator differs in step 3 and step 4 (see Paper vs code).
# Leverage SHAP with the released per-size sampler [alg. 1] [app. J]
# Input: n players, v (set function), m (budget; paper requires m >= n)
# Output: phi, shape (n,), with sum(phi) = v(all) - v(empty)
def leverage_shap(n, v, m):
# Cap the budget at 2^n and round it up to an even number [alg. 1]
m = min(m, 2 ** n)
m = m + m % 2
# Two evaluations go to the empty and the full coalition [alg. 1]
v_empty = v(zeros(n))
v_all = v(ones(n))
# Expected rows per size is min(C(n, s), c), with c chosen so the
# total is m - 2 [eq. 13] [code: sampling.py#L85-L142]
expected = expected_rows_per_size(n, m - 2)
# Integer counts per size, symmetric under s <-> n - s
# [code: sampling.py#L172-L175]
counts = symmetric_round(expected)
pairs = []
for size in range(1, n // 2 + 1):
# Middle size of even n: a pair holds two subsets of this size,
# so half as many pairs are drawn
# [app. J] [code: sampling.py#L189-L195]
is_middle = 2 * size == n
pair_count = counts[size] // 2 if is_middle else counts[size]
# Draw subsets of this size uniformly, without replacement; each one
# is paired with its complement [§3.2] [app. J]
for z in draw_subsets(n, size, pair_count, is_middle):
pairs.append((z, complement(z)))
rows = [row for pair in pairs for row in pair]
# One evaluation per row: m - 2 in total [alg. 1]
values = [v(row) for row in rows]
# Target: value minus empty value, minus this row's share of the gap
# [alg. 1] [code: leverage_shap.py#L49-L51]
targets = [
value - v_empty - (v_all - v_empty) * sum(row) / n
for row, value in zip(rows, values)
]
# Weight: kernel weight w(|z|) over the realised inclusion probability
# counts[s] / C(n, s) [eq. 4] [code: leverage_shap.py#L52-L53]
weights = [
kernel_weight(n, sum(row)) / (counts[sum(row)] / comb(n, sum(row)))
for row in rows
]
# Projection that removes the all-ones direction, so the efficiency
# constraint holds by construction [§3, app. K]
P = identity(n) - ones(n, n) / n
design = rows @ P
# Minimum-norm weighted least squares, not an explicit inverse
# [code: leverage_shap.py#L63-L66]
x = weighted_min_norm_lstsq(design, targets, weights)
# Give back each player an equal share of the efficiency gap [alg. 1]
return x + (v_all - v_empty) / nCost: the model is called m times, and the extra work is O(m·n² + n³) on top of those calls app. J. The paper notes that the model calls usually dominate app. J.
Theory: the main result bounds the regression objective. With m = O(n log(n/δ) + n/(εδ)) evaluations in expectation, the returned vector has objective at most (1 + ε) times the optimum, with probability 1 − δ, for constant δ §1, eq. 5. A corollary converts this to the squared ℓ2 error of φ, with a problem-specific factor γ = ‖Aφ − b‖² / ‖Aφ‖² §4. The paper reports γ only for n ≤ 16 app. F.
Hyperparameters
| Name | Value | Where | Notes |
|---|---|---|---|
| Budget m (evaluations) | 5n, 10n, 20n, 40n, 80n, 160n | §5 run.py | Table 1 and the noise study use 10n tab. 1 app. D |
| Budget floor | m ≥ n in Algorithm 1 | alg. 1 | Released code raises values below 6 to 6 leverage_shap.py |
| Budget rounding | round up to even; cap at 2^n | alg. 1 sampling.py | Odd budgets are rounded up |
| Noise σ (set-function noise) | 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1, 0.5, 1 | app. D run.py | Gaussian noise on each observed v(S); m = 10n |
| Runs per setting | 100 | §5 run.py | Median and quartiles reported |
| Error metric | ‖φ − φ̃‖² / ‖φ‖² | §5 benchmark.py | Relative squared ℓ2 error |
| Model | XGBoost, 100 estimators, max depth 4, other defaults | §5 benchmark.py | Fitted on the full dataset in code; split not stated in paper |
| XGBoost version | ≤ 2.0.3 | pyproject.toml | Declared as a dependency in the package |
| Ground truth | Tree SHAP, exact | §5 official_shap.py | Computed on the noiseless model |
| Baseline | not stated in paper | §5 | Code: column means of the data datasets.py |
| Explicand | one random row per run; selection not further stated | app. F tab. 3 | Code resamples any coordinate that equals the baseline datasets.py |
| Optimized Kernel SHAP | SHAP library KernelExplainer, nsamples = m, l1_reg = False | §5 official_shap.py | Baseline in all main comparisons |
| Scale c | solved from the budget | alg. 1 eq. 13 | Not a tunable hyperparameter |
| Feature counts n | IRIS 4, California 8, Diabetes 10, Adult 12 | tab. 3 | n for NHANES, Communities, Correlated and Independent not stated |
Results
Author-reported. Setup: eight datasets from the SHAP library, XGBoost model, exact Tree SHAP ground truth, 100 random runs per setting, error is relative squared ℓ2 error §5. Values at m = 10n tab. 1. Q1–Q3 are the first to third quartiles. Leverage SHAP is the best method in every column except ties tab. 1.
Table 1: relative squared ℓ2 error at m = 10n tab. 1
| Method / statistic | IRIS | California | Diabetes | Adult | Correlated | Independent | NHANES | Communities |
|---|---|---|---|---|---|---|---|---|
| Kernel SHAP | ||||||||
| Mean | 0.0326 | 0.03 | 0.0592 | 0.0596 | 0.0471 | 0.0269 | 0.0542 | 0.118 |
| Q1 | 1.03e-05 | 0.00689 | 0.0123 | 0.0196 | 0.0264 | 0.0142 | 0.0175 | 0.0578 |
| Q2 | 0.000259 | 0.0177 | 0.0237 | 0.0412 | 0.0405 | 0.0207 | 0.038 | 0.0876 |
| Q3 | 0.034 | 0.0417 | 0.0545 | 0.0844 | 0.0556 | 0.0315 | 0.0789 | 0.139 |
| Optimized Kernel SHAP | ||||||||
| Mean | 4.84e-09 | 0.00301 | 0.00791 | 0.0104 | 0.0117 | 0.00507 | 0.00713 | 0.0231 |
| Q1 | 1.66e-13 | 0.000805 | 0.00147 | 0.00309 | 0.00432 | 0.00214 | 0.00151 | 0.00879 |
| Q2 | 2.17e-13 | 0.00205 | 0.00367 | 0.00491 | 0.00848 | 0.00459 | 0.00408 | 0.0161 |
| Q3 | 2.69e-10 | 0.00391 | 0.00806 | 0.0109 | 0.0159 | 0.00691 | 0.00827 | 0.0301 |
| Leverage SHAP | ||||||||
| Mean | 4.84e-09 | 0.000249 | 0.00227 | 0.00416 | 0.00662 | 0.00257 | 0.00505 | 0.0139 |
| Q1 | 1.66e-13 | 4.23e-05 | 0.000202 | 0.000424 | 0.00223 | 0.000936 | 0.000816 | 0.00575 |
| Q2 | 2.17e-13 | 0.000119 | 0.000991 | 0.00102 | 0.00484 | 0.00233 | 0.00232 | 0.00916 |
| Q3 | 2.69e-10 | 0.000277 | 0.00259 | 0.00362 | 0.00865 | 0.00378 | 0.00407 | 0.0213 |
Table 2: error ratio, Leverage SHAP / Optimized Kernel SHAP, by budget tab. 2
A value of 1 means m ≥ 2^n, where both methods are exact tab. 2.
| Dataset | 5n | 10n | 20n | 40n | 80n | 160n |
|---|---|---|---|---|---|---|
| IRIS | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |
| California | 0.0894 | 0.0824 | 0.0471 | 1.00 | 1.00 | 1.00 |
| Diabetes | 0.184 | 0.287 | 0.261 | 0.181 | 0.151 | 1.00 |
| Adult | 0.527 | 0.400 | 0.328 | 0.439 | 0.345 | 0.211 |
| Correlated | 0.588 | 0.568 | 0.660 | 0.657 | 0.727 | 0.674 |
| Independent | 0.492 | 0.507 | 0.625 | 0.654 | 0.618 | 0.651 |
| NHANES | 0.706 | 0.708 | 0.685 | 0.736 | 0.753 | 0.720 |
| Communities | 0.531 | 0.601 | 0.598 | 0.659 | 0.671 | 0.697 |
The paper's headline is 50.0% of the error of Optimized Kernel SHAP on average, computed over the 38 entries that are not 1 tab. 2. See Pitfalls for what this average excludes.
Table 3: quartiles of γ over 100 runs, small-n datasets tab. 3
| Dataset | n | Q1 | Q2 | Q3 |
|---|---|---|---|---|
| IRIS | 4 | 0.000234 | 0.142 | 0.991 |
| California | 8 | 0.161 | 0.297 | 0.44 |
| Diabetes | 10 | 0.182 | 0.321 | 0.528 |
| Adult | 12 | 0.171 | 0.4 | 0.729 |
Other results, described in words:
- Sample size fig. 3: Kernel SHAP has the highest error in all settings. Leverage SHAP is below the median of Optimized Kernel SHAP on the small-n datasets. On Correlated and Independent its third quartile is about the median of Optimized Kernel SHAP. On NHANES and Communities, its upper quartile sits at roughly one and a half times that median fig. 3.
- Noise fig. 4: Leverage SHAP is best at low and moderate noise (σ ≤ 0.1) on every dataset. At σ ≥ 0.5 it is close to Optimized Kernel SHAP.
- Ablations tab. 4 app. G: paired sampling reduces error by a factor of about four or more. Without-replacement sampling helps for small n, by a factor between 1.1 and 10. Unpaired Leverage SHAP is much worse; on California at 10n its mean error is 0.0124 against 0.000249 for Leverage SHAP tab. 4.
- Objective error fig. 10, fig. 11 app. H: the regression objective, not φ, is shown. Leverage SHAP or its Binomial variant gives the best results in most settings with m < 2^n.
Paper vs code
Code: official repository rtealwitter/leverageshap, commit 9702c2cc6386e13fca20b9caeb8747dedf253cef, cloned with --depth 1 [paper footnote, §5]. The repository owner is an author of the paper.
- Sampler. The theorem covers the independent sampler of Algorithm 2. The released estimator draws fixed per-size counts, rounded and symmetric, instead §3.2 sampling.py. The paper says so and writes "we believe the guarantees still hold" §3.2.
- Minimum budget. Algorithm 1 takes m ≥ n alg. 1. The code raises any budget below 6 to 6 with a printed warning leverage_shap.py.
- Scale search. Algorithm 1 uses a binary search for c alg. 1, line 2. The code inverts the same piecewise-linear sum in closed form, with the same target m − 2 sampling.py.
- Reweighting. Algorithm 1 weights each row by w(|z|) / min(1, 2c·ℓ_z) alg. 1, line 499. The code weights by w(|z|) divided by the realised per-size inclusion probability counts[s] / C(n, s) leverage_shap.py sampling.py.
- Middle size. Appendix J and the code agree: for even n, the middle size draws half as many pairs from subsets of size n/2 − 1 with the last player always included app. J sampling.py.
- Appendix G text vs appendix J. Appendix G says the Binomial variant draws middle-layer pairs from Binomial(C(n, n/2)/2, p) "as in Algorithm 2" app. G. Appendix J says the opposite, that the draw is from Binomial(C(n−1, s−1), p) "rather than halving" app. J. The ablation code uses C(n−1, s−1) ablations.py. Treat the appendix G sentence as a typo.
- Model calls. Algorithm 1 uses m − 2 calls on sampled rows plus two on v(∅) and v(all) alg. 1. The code matches this total.
Pitfalls
- Theorem and code differ. The guarantee is for the independent sampler of Algorithm 2, not the deterministic per-size counts used in the released code and every reported experiment §3.2. Expect the released estimator to behave as the paper's experiments show, not as the proof guarantees.
- Realised budget. In the deterministic version the number of evaluations equals the rounded budget. In the Binomial variant it is random; the paper reports a mean within 2.7% of min(m, 2^n) app. G.
- Small budgets. Below n evaluations the projected system is rank-deficient. When m < 6 the code uses 6 evaluations instead, with a printed warning leverage_shap.py. Report the realised count, not the requested one.
- Overflow for large n. The released sampler uses integer combinations. When the count is too large for numpy, it falls back to drawing with replacement, with no warning sampling.py. The paper reports that this fallback affects NHANES and Communities in its ablation runs app. G.
- Noise touches the empty and full coalitions. The noise wrapper perturbs every prediction, including v(∅) and v(all), because the edge-case calls go through the same model benchmark.py. The paper says only that the estimators observe v(S) + ζ app. D.
- Numerical sensitivity. AᵀA is singular by construction, so use the minimum-norm least-squares solution, not an inverse leverage_shap.py §3. For small n the objective error can fall below 1 because of numerical instability fig. 10 caption.
- The "50%" average. The headline average is over the 38 entries of Table 2 that are not 1. Those 38 are the budgets below 2^n tab. 2. If the ten entries equal to 1 are included, the average ratio is about 0.60 (my arithmetic from Table 2), a reduction of about 40%.
- Asymptotic claim. The abstract's O(n log n) holds when ε and δ are treated as constants. The theorem allows constant δ, and its bound also has a 1/ε term §1.
- γ is not controlled by the theorem. The corollary's ℓ2 bound scales with γ. The paper measures γ only for n ≤ 16 app. F, so the bound's size is unknown for larger n.
- Baseline choice is not stated. The paper does not say how the baseline is chosen. The code uses column means and a random explicand. Shapley values depend on the baseline through v(S), so another baseline changes the target datasets.py.
- Names. "Kernel SHAP" in the paper's ablations is the paper's own unpaired regression. "Optimized Kernel SHAP" is the SHAP library baseline used in the main comparisons app. G §5.
- Hardness. A multiplicative guarantee on every φ_i is NP-hard in general, which is why the guarantee is on the objective app. C.
Lineage
- Builds on: Kernel SHAP (Lundberg & Lee, 2017), cited as the baseline in §1. No card.
- Compared against: Optimized Kernel SHAP and Permutation SHAP from the SHAP library, and the paper's own Kernel SHAP variants §5 app. G.
- Uses an idea from active learning: leverage-score sampling for regression §1.3.
- Related follow-up named by the paper: a unified framework that covers Kernel SHAP and Leverage SHAP and gives non-asymptotic guarantees for Kernel SHAP, by Chen et al. (2025) §1.3.
Source and license
Adapted from “Provably Accurate Shapley Value Estimation via Leverage Score Sampling” by Christopher Musco, R. Teal Witter (arXiv:2410.01917), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/rtealwitter/leverageshap at commit 9702c2cc6386 (MIT). Any quoted code is shown under that license.