shapiq.approximator.LeverageSHAP¶
- class shapiq.approximator.LeverageSHAP(n, *, pairing_trick=True, sampling_weights=None, random_state=None, deterministic_counts=True, **kwargs)[source]¶
Bases:
Regression[Literal[‘SV’]]Leverage SHAP approximator for Shapley values.
Leverage SHAP (Musco and Witter, 2025 Musco and Witter [2025]) recovers Shapley values as the solution of a weighted least-squares problem over sampled coalitions, like KernelSHAP, but samples coalitions proportional to their statistical leverage scores, which have the closed form
l_z = 1/C(n, ||z||)(Lemma 3.2). Implementation of Algorithm 1:For the deterministic default, normalize the budget to an even number without exceeding it. Solve for the oversampling parameter
cso thatm - 2 = sum_{s=1}^{n-1} min(C(n, s), 2c)(Eq. 12); two evaluations are reserved for the empty and grand coalitions.Draw coalition pairs
(z, z̄)without replacement (Algorithm 2). By default (deterministic_counts=True) each size’s pair count is fixed to the expectation of the Binomial draw, largest-remainder rounded so the total is exact – stratification in the spirit of SVARM Kolpaczki et al. [2024]; withdeterministic_counts=Falseit is drawn at random as Algorithm 2 states. Sizes whose layer fits within2care enumerated exhaustively.Reweight each row by the inverse of its inclusion probability. For the deterministic default this probability is the realized per-size count divided by
C(n, s); for the Binomial variant it ismin(1, 2c * l_z).Project out the efficiency constraint (Lemma 3.1), solve by weighted least squares, and add the efficiency offset back.
Note
The deterministic default follows the fixed-per-size design used by the paper’s released implementation and reported experiments. To preserve shapiq’s hard budget ceiling, an odd budget is rounded down rather than up as in that implementation; largest-remainder ties can also select a different size. The evaluation count is exactly
2 + 2 * ((min(budget, 2**n) - 2) // 2). The paper’s accuracy theorem is proved for the Binomialdeterministic_counts=Falsevariant only (Musco and Witter, 2025, end of Sec. 4).Example
>>> from shapiq.approximator import LeverageSHAP >>> from shapiq_games.synthetic import DummyGame >>> n = 5 >>> game = DummyGame(n=n, interaction=(1, 2)) >>> approximator = LeverageSHAP(n=n, random_state=42) >>> sv_estimates = approximator.approximate(budget=100, game=game) >>> print(sv_estimates.values) [0. 0.2 0.7 0.7 0.2 0.2]
See also
KernelSHAP: The original KernelSHAP approximator that Leverage SHAP refines.
Initialize the LeverageSHAP approximator.
- Parameters:
n (
int) – The number of players.pairing_trick (
bool) – IfTrue(default), every sampled coalition’s complement is also included (Algorithm 1’s design). IfFalse, the same per-size counts are drawn independently instead – the paper’s “without paired sampling” ablation. Both modes sample without replacement.sampling_weights (
ndarray|None) – Inert; kept only for interface compatibility.random_state (
int|None) – The random state of the estimator. Defaults toNone.deterministic_counts (
bool) – IfTrue(default), fix each size’s pair count to the expectation of Algorithm 2’s Binomial draw (largest-remainder rounded, exact total); ifFalse, draw it at random. See the class docstring’s Note.**kwargs (
Any) – Additional keyword arguments (not used, only for compatibility).
- approximate(budget, game, *args, **kwargs)[source]¶
Approximate the Shapley values via leverage-score-guided sampling.
- Parameters:
- Return type:
- Returns:
The estimated Shapley values as an
InteractionValuesobject.estimation_budgetreports the realized number of evaluations: exact withdeterministic_counts=True(see the class Note), a random draw that concentrates around the budget otherwise.- Raises:
ValueError – If
budgetis less than2(the empty and grand coalitions must both be evaluated), or if the game returns non-finite (NaN/Inf) values.