shapiq.explainer.TabPFNExplainer¶

class shapiq.explainer.TabPFNExplainer(model, data, labels, *, index='SV', max_order=1, x_test=None, empty_prediction=None, class_index=None, approximator='auto', verbose=False)[source]¶

Bases: TabularExplainer

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

The TabPFNExplainer class is the dedicated interface for the shapiq package and TabPFN Hollmann et al.[1] models such as the TabPFNClassifier and TabPFNRegressor. The explainer does not rely on classical imputation methods and is optimized for TabPFN’s in-context learning approach. The explanation paradigm for TabPFN is described in Rundel et al.[2]. In essence the explainer is a wrapper around the :class:~`shapiq.explainer.tabular.TabularExplainer` class and uses the same API.

References

Initialize the TabPFNExplainer.

Parameters:
  • model (Any) – Either a TabPFNClassifier or TabPFNRegressor model to be explained.

  • data (ndarray) – The background data to use for the explainer as a 2-dimensional array with shape (n_samples, n_features). This data is used to contextualize the model on.

  • labels (ndarray) – The labels for the background data as a 1-dimensional array with shape (n_samples,). This data is used to contextualize the model on.

  • approximator (Union[Approximator, Literal['auto', 'spex', 'montecarlo', 'svarm', 'permutation', 'regression']]) – 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").

  • x_test (ndarray | None) – An optional test data set to compute the model’s empty prediction (average prediction) on. If no test data and empty_prediction is set to None the last 20% of the background data is used as test data and the remaining 80% as training data for contextualization. Defaults to None.

  • empty_prediction (float | None) – Optional value for the model’s average prediction on an empty data point (all features missing). If provided, overrides parameters in x_test. and skips the computation of the empty prediction. Defaults to None.

  • 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.

  • verbose (bool) – Whether to show a progress bar during the computation. Defaults to False. Note that verbosity can slow down the computation for large datasets.

property is_available: bool¶

Check if the TabPFN package is available.