shapiq.approximator.KernelSHAPΒΆ

class shapiq.approximator.KernelSHAP(n, *, pairing_trick=False, sampling_weights=None, random_state=None, **kwargs)[source]ΒΆ

Bases: Regression[Literal[β€˜SV’]]

The KernelSHAP regression approximator for estimating the Shapley values.

The KernelSHAP approximator is described in Lundberg and Lee (2017) Lundberg and Lee [2017]. The method estimates the Shapley values by solving a weighted regression problem, where the Shapley values are the coefficients of the regression problem.

Example

>>> from shapiq_games.synthetic import DummyGame
>>> from shapiq.approximator import KernelSHAP
>>> game = DummyGame(n=5, interaction=(1, 2))
>>> approximator = KernelSHAP(n=5)
>>> approximator.approximate(budget=100, game=game)
InteractionValues(
    index=SV, order=1, estimated=False, estimation_budget=32,
    values={
        (0,): 0.2,
        (1,): 0.7,
        (2,): 0.7,
        (3,): 0.2,
        (4,): 0.2,
    }
)

See also

  • KernelSHAPIQ: The KernelSHAPIQ

    approximator for estimating the Shapley interaction index (SII) and the k-Shapley interaction index (k-SII).

  • RegressionFSII: The Faithful KernelSHAP

    approximator for estimating the Faithful Shapley interaction index (FSII).

Initialize the KernelSHAP approximator.

Parameters:
  • n (int) – The number of players.

  • pairing_trick (bool) – If True, the pairing trick is applied to the sampling procedure. Defaults to False.

  • sampling_weights (ndarray | None) – An optional array of weights for the sampling procedure. The weights must be of shape (n + 1,) and are used to determine the probability of sampling a coalition of a certain size. Defaults to None.

  • random_state (int | None) – The random state of the estimator. Defaults to None.

  • **kwargs (Any) – Additional keyword arguments (not used only for compatibility).

valid_indices: tuple[Literal['SV'], ...] = ('SV',)ΒΆ

The valid indices for the regression approximator. Overrides the valid indices of the base class Approximator.