shapiq.explainer.TabularExplainerΒΆ

class shapiq.explainer.TabularExplainer(model, data, *, class_index=None, imputer='marginal', approximator='auto', index='SV', max_order=1, random_state=None, verbose=False, **kwargs)[source]ΒΆ

Bases: Explainer

The tabular explainer as the main interface for the shapiq package.

The TabularExplainer class is the main interface for the shapiq package and tabular data. It can be used to explain the predictions of any model by estimating the Shapley interaction values.

Variables:
  • index – Type of Shapley interaction index to use.

  • data – A background data to use for the explainer.

Parameters:
  • model (Any | Game | Callable[[ndarray], ndarray])

  • data (np.ndarray)

  • class_index (int | None)

  • imputer (Imputer | TabularExplainerImputers)

  • approximator (Literal['auto'] | TabularExplainerApproximators | Approximator[TabularExplainerIndices])

  • index (TabularExplainerIndices)

  • max_order (int)

  • random_state (int | None)

  • verbose (bool)

  • kwargs (Any)

Properties:

baseline_value: A baseline value of the explainer.

Initializes the TabularExplainer.

Parameters:
  • model (Any) – The model to be explained as a callable function expecting data points as input and returning 1-dimensional predictions.

  • data (ndarray) – A background dataset to be used for imputation.

  • class_index (int | None) – The class index of the model to explain. Defaults to None, which will set the class index to 1 per default for classification models and is ignored for regression models.

  • imputer (Union[Imputer, Literal['marginal', 'baseline', 'conditional']]) – Either an Imputer as implemented in the imputer module, or a literal string from ["marginal", "baseline", "conditional"]. Defaults to "marginal", which initializes the default MarginalImputer with its default parameters or as provided in kwargs.

  • approximator (Union[Literal['auto'], Literal['spex', 'montecarlo', 'svarm', 'permutation', 'regression'], Approximator[Literal['SV', 'SII', 'k-SII', 'STII', 'FSII', 'BV', 'BII', 'FBII']]]) – An Approximator object to use for the explainer or a literal string from ["auto", "spex", "montecarlo", "svarm", "permutation"]. Defaults to "auto" which automatically selects: KernelSHAP for "SV", KernelSHAPIQ for "SII"/"k-SII", RegressionFSII for "FSII", RegressionFBII for "FBII", and SVARMIQ for "STII".

  • index (Literal['SV', 'SII', 'k-SII', 'STII', 'FSII', 'BV', 'BII', 'FBII']) – The index to explain the model with. Defaults to "SV" which computes the Shapley value. Options: "SV" (Shapley value), "k-SII" (k-Shapley Interaction Index), "FSII" (Faithful Shapley Interaction Index), "FBII" (Faithful Banzhaf Interaction Index, becomes BV for order 1), "STII" (Shapley Taylor Interaction Index), "SII" (Shapley Interaction Index).

  • max_order (int) – The maximum order of interactions to be computed. Set to 1 for no interactions (i.e, for Shapley values "SV" or Banzhaf values "BV").

  • random_state (int | None) – The random state to initialize Imputer and Approximator with. Defaults to None.

  • verbose (bool) – Whether to show a progress bar during the computation. Defaults to False.

  • **kwargs (Any) – Additional keyword-only arguments passed to the imputers implemented in imputer.

explain_function(x, budget, *, random_state=None)[source]ΒΆ

Explains the model’s predictions.

Parameters:
  • x (ndarray) – The data point to explain as a 2-dimensional array with shape (1, n_features).

  • budget (int) – The budget to use for the approximation. It indicates how many coalitions are sampled, thus high values indicate more accurate approximations, but induce higher computational costs.

  • random_state (int | None) – The random state to re-initialize Imputer and Approximator with. Defaults to None, which will not set a random state.

Return type:

InteractionValues

Returns:

An object of class InteractionValues containing the computed interaction values.

property baseline_value: floatΒΆ

Returns the baseline value of the explainer.