> ## Documentation Index
> Fetch the complete documentation index at: https://docs.priorlabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> TabPFN-3 and later versions support up to 1,000,000 rows, subject to feature count and checkpoint/API limits.
> For large datasets, use per-estimator subsampling, e.g. inference_config={"SUBSAMPLE_SAMPLES": 100_000}, in TabPFNClassifier or TabPFNRegressor from tabpfn or tabpfn_client.
> Pass raw pandas DataFrames to fit and predict. Categorical strings/categories, raw text, and missing feature values are handled automatically; no manual integer/one-hot encoding, imputation, scaling, or outlier removal is needed.

# Shapley explainers

> Create Shapley explainers and prepare their results for SHAP plots.

<Info>
  Looking for usage documentation? Check out [Interpretability](/capabilities/interpretability) and [KV cache](/capabilities/kv-cache).
</Info>

<div className="python-reference-heading">
  <h2 id="get-tabpfn-imputation-explainer">
    `shapiq.get_tabpfn_imputation_explainer`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/interpretability/shapiq.py#L249" aria-label="View source for shapiq.get_tabpfn_imputation_explainer"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Gets a [`TabularExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html) from shapiq with imputation-based feature removal.

The explainer uses an imputation-based paradigm of feature removal \[3]:
for each coalition, masked features are filled by an imputer and TabPFN
is queried for a prediction. The training set is fixed across coalitions,
so the KV cache makes this dramatically faster than the
remove-and-recontextualize path (cf. [`get_tabpfn_explainer`](/api-reference/python/tabpfn-extensions/interpretability/shapley-explainers#get-tabpfn-explainer)). A
warning is emitted if the model is not configured for the cache.

The default imputer is `"baseline"` (one fixed fill value per feature,
so each coalition costs exactly one forward pass). Marginal/conditional
imputers draw multiple samples per coalition and are 50-100x slower in
practice without commensurate gains for in-context models — switch to
them only if you have a specific reason.

```python theme={null}
shapiq.get_tabpfn_imputation_explainer(
    model: tabpfn.TabPFNRegressor | tabpfn.TabPFNClassifier,
    data: pd.DataFrame | np.ndarray,
    index: str = "k-SII",
    max_order: int = 2,
    imputer: str = "baseline",
    class_index: int | None = None,
    approximator = None,
    random_state: int | None = None,
    **kwargs,
)
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="get-tabpfn-imputation-explainer-model" /><code className="python-reference-parameter">model</code> | <code className="python-reference-type"><a href="/api-reference/python/tabpfn/regressor/configuration#constructor">tabpfn.Tab<wbr />PFN<wbr />Regressor</a> \| <a href="/api-reference/python/tabpfn/classifier/configuration#constructor">tabpfn.Tab<wbr />PFN<wbr />Classifier</a></code> | Required | The TabPFN model to explain. Should be constructed with `fit_mode="fit_with_cache"` to engage the KV-cache fast path. |
  | <span id="get-tabpfn-imputation-explainer-data" /><code className="python-reference-parameter">data</code> | <code className="python-reference-type"><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html">pd.Data<wbr />Frame</a> \| <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a></code> | Required | The background data to use for the explainer. |
  | <span id="get-tabpfn-imputation-explainer-index" /><code className="python-reference-parameter">index</code> | <code className="python-reference-type">str</code> | `"k-SII"` | The explanation index. Defaults to `"k-SII"`. For Shapley values like SHAP, use `index="SV"` with `max_order=1`. See the [shapiq reference](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html) for the available indices. |
  | <span id="get-tabpfn-imputation-explainer-max-order" /><code className="python-reference-parameter">max\_<wbr />order</code> | <code className="python-reference-type">int</code> | `2` | The maximum order of interactions to consider. Defaults to `2`. |
  | <span id="get-tabpfn-imputation-explainer-imputer" /><code className="python-reference-parameter">imputer</code> | <code className="python-reference-type">str</code> | `"baseline"` | The imputation method to use. See [`shapiq.TabularExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html) documentation for more information and an up-to-date list of available imputation methods. |
  | <span id="get-tabpfn-imputation-explainer-class-index" /><code className="python-reference-parameter">class\_<wbr />index</code> | <code className="python-reference-type">int \| None</code> | `None` | The class index of the model to explain. If not provided, the class index will be set to `1` per default for classification models. This argument is ignored for regression models. Defaults to `None`. |
  | <span id="get-tabpfn-imputation-explainer-approximator" /><code className="python-reference-parameter">approximator</code> | — | `None` | The shapiq approximator to estimate the coalition game with. Defaults to `None`, which routes to the recommended estimator: `OddSHAP` for first-order Shapley values (`index="SV"`) and `ProxySHAP` for interaction indices (see `_resolve_approximator`). Pass a shapiq `Approximator` instance or a literal string (e.g. `"auto"`) to override the routing. |
  | <span id="get-tabpfn-imputation-explainer-random-state" /><code className="python-reference-parameter">random\_<wbr />state</code> | <code className="python-reference-type">int \| None</code> | `None` | Seed forwarded to the routed `OddSHAP`/`ProxySHAP` approximator for reproducible coalition sampling. Has no effect when an explicit `approximator` is passed or the `"auto"` fallback is used. Defaults to `None`. |
  | <span id="get-tabpfn-imputation-explainer-kwargs" /><code className="python-reference-parameter">\*\*kwargs</code> | — | — | Additional keyword arguments to pass to the explainer.<br /><br />See [`shapiq.TabularExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html) for keyword options. |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type"><a href="https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html">shapiq.Tabular<wbr />Explainer</a></code> | Explainer that imputes masked features while keeping the training data fixed. |
</div>

**References**

* **\[1]** [shapiq repository](https://github.com/mmschlk/shapiq).
* **\[2]** Muschalik et al. (2024). [shapiq: Shapley Interactions for Machine Learning](https://openreview.net/forum?id=knxGmi6SJi).
* **\[3]** Lundberg and Lee (2017). [A Unified Approach to Interpreting Model Predictions](https://proceedings.neurips.cc/paper/2017/hash/8a20a8621978632d76c43dfd28b67767-Abstract.html).

***

<div className="python-reference-heading">
  <h2 id="get-tabpfn-inf-explainer">
    `shapiq.get_tabpfn_inf_explainer`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/interpretability/shapiq.py#L366" aria-label="View source for shapiq.get_tabpfn_inf_explainer"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Gets a [`TabularExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html) that masks missing features with `+inf`.

When a coalition leaves a feature out, this explainer sets that feature to
`+inf` and lets TabPFN's native missing-value handling absorb it as
"missing" — no sampling from a background distribution, just one forward
pass per coalition. Since the training set never changes across
coalitions, this is the fastest path on TabPFN v3: construct the model
with `fit_mode="fit_with_cache"` and set
`model.executor_.keep_cache_on_device = True` after `.fit()` so every
coalition evaluation reuses one on-device KV cache.

This differs from [`get_tabpfn_imputation_explainer`](/api-reference/python/tabpfn-extensions/interpretability/shapley-explainers#get-tabpfn-imputation-explainer) — that one
*samples* the absent features from a background distribution, so their
values are drawn from the data. Here nothing is sampled: a masked feature
is genuinely missing and TabPFN decides how to handle it. `+inf` (rather
than `NaN`) is used deliberately: `NaN` is transformed by TabPFN's
preprocessing pipeline before it reaches the model, whereas `+inf` is
carried through and handled natively as missingness.

IMPORTANT: this requires the model to be constructed with
`inference_config={"PASSTHROUGH_INF": True}` (available in
`tabpfn>=8.1.0`). Without it, TabPFN rejects non-finite inputs at
validation and this function raises `ValueError` up front rather than
letting every coalition evaluation fail later. The remote backends forward
the flag to the TabPFN they run, so this path works there too.

```python theme={null}
shapiq.get_tabpfn_inf_explainer(
    model: tabpfn.TabPFNRegressor | tabpfn.TabPFNClassifier,
    data: pd.DataFrame | np.ndarray,
    index: str = "SV",
    max_order: int = 1,
    class_index: int | None = None,
    approximator = None,
    random_state: int | None = None,
    **kwargs,
)
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="get-tabpfn-inf-explainer-model" /><code className="python-reference-parameter">model</code> | <code className="python-reference-type"><a href="/api-reference/python/tabpfn/regressor/configuration#constructor">tabpfn.Tab<wbr />PFN<wbr />Regressor</a> \| <a href="/api-reference/python/tabpfn/classifier/configuration#constructor">tabpfn.Tab<wbr />PFN<wbr />Classifier</a></code> | Required | The TabPFN model to explain. Must be constructed with `inference_config={"PASSTHROUGH_INF": True}`. For the v3 KV-cache fast path, also pass `fit_mode="fit_with_cache"` before `.fit(X, y)` and set `model.executor_.keep_cache_on_device = True` afterwards. |
  | <span id="get-tabpfn-inf-explainer-data" /><code className="python-reference-parameter">data</code> | <code className="python-reference-type"><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html">pd.Data<wbr />Frame</a> \| <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a></code> | Required | Background data. Only its shape (number of features) and a single row for shapiq's compatibility check are used — it does **not** drive the masking, since absent features are replaced with `+inf` rather than sampled. |
  | <span id="get-tabpfn-inf-explainer-index" /><code className="python-reference-parameter">index</code> | <code className="python-reference-type">str</code> | `"SV"` | The Shapley-style index to compute. Defaults to `"SV"` (plain Shapley values). See shapiq docs for alternatives. |
  | <span id="get-tabpfn-inf-explainer-max-order" /><code className="python-reference-parameter">max\_<wbr />order</code> | <code className="python-reference-type">int</code> | `1` | Maximum interaction order. Defaults to `1` (individual feature attributions, equivalent to classical SHAP values). |
  | <span id="get-tabpfn-inf-explainer-class-index" /><code className="python-reference-parameter">class\_<wbr />index</code> | <code className="python-reference-type">int \| None</code> | `None` | Class to explain for classification models. Defaults to `None` (shapiq uses class 1). Ignored for regression. |
  | <span id="get-tabpfn-inf-explainer-approximator" /><code className="python-reference-parameter">approximator</code> | — | `None` | The shapiq approximator to estimate the coalition game with. Defaults to `None`, which routes to the recommended estimator: `OddSHAP` for first-order Shapley values (`index="SV"`, the default here) and `ProxySHAP` for interaction indices (see `_resolve_approximator`). Pass a shapiq `Approximator` instance or a literal string (e.g. `"auto"`) to override. |
  | <span id="get-tabpfn-inf-explainer-random-state" /><code className="python-reference-parameter">random\_<wbr />state</code> | <code className="python-reference-type">int \| None</code> | `None` | Seed forwarded to the routed `OddSHAP`/`ProxySHAP` approximator for reproducible coalition sampling. Has no effect when an explicit `approximator` is passed or the `"auto"` fallback is used. Defaults to `None`. |
  | <span id="get-tabpfn-inf-explainer-kwargs" /><code className="python-reference-parameter">\*\*kwargs</code> | — | — | Passed through to [`shapiq.TabularExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html). |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type"><a href="https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html">shapiq.Tabular<wbr />Explainer</a></code> | Explainer that replaces masked features with `+inf`. |
</div>

**Raises**

`ValueError`

If `model` can be introspected and does not have
`PASSTHROUGH_INF` enabled.

**Example**

```python theme={null}
>>> from tabpfn import TabPFNClassifier
>>> from tabpfn_extensions.interpretability import shapiq as tpe_shapiq
>>> clf = TabPFNClassifier(
...     inference_config={"PASSTHROUGH_INF": True},
...     fit_mode="fit_with_cache",
... )
>>> clf.fit(X_train, y_train)
>>> clf.executor_.keep_cache_on_device = True  # optional but faster
>>> explainer = tpe_shapiq.get_tabpfn_inf_explainer(
...     model=clf, data=X_train, class_index=1
... )
>>> iv = explainer.explain(x=X_test[0], budget=2 ** X_train.shape[1])
```

***

<div className="python-reference-heading">
  <h2 id="get-tabpfn-explainer">
    `shapiq.get_tabpfn_explainer`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/interpretability/shapiq.py#L152" aria-label="View source for shapiq.get_tabpfn_explainer"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Get a [`TabPFNExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabPFNExplainer.html) (remove-and-recontextualize) from shapiq.

The explainer uses the remove-and-recontextualize paradigm of model
explanation \[2] \[3]: for each coalition `S`, TabPFN is re-fit on the
columns in `S` and predictions are made with that re-fitted model. This
is expensive because every coalition triggers a fresh fit.

NOTE: This path **does not benefit from the KV cache** even when the
underlying model is configured with `fit_mode="fit_with_cache"`. Each
coalition does exactly one fit + one predict, so there are no repeated
predicts to amortize the cache over. If you want the cache to actually
speed things up, prefer [`get_tabpfn_imputation_explainer`](/api-reference/python/tabpfn-extensions/interpretability/shapley-explainers#get-tabpfn-imputation-explainer) (which
runs `budget` predicts against a single fit).

```python theme={null}
shapiq.get_tabpfn_explainer(
    model: tabpfn.TabPFNRegressor | tabpfn.TabPFNClassifier,
    data: pd.DataFrame | np.ndarray,
    labels: pd.DataFrame | np.ndarray,
    index: str = "k-SII",
    max_order: int = 2,
    class_index: int | None = None,
    approximator = None,
    random_state: int | None = None,
    **kwargs,
)
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="get-tabpfn-explainer-model" /><code className="python-reference-parameter">model</code> | <code className="python-reference-type"><a href="/api-reference/python/tabpfn/regressor/configuration#constructor">tabpfn.Tab<wbr />PFN<wbr />Regressor</a> \| <a href="/api-reference/python/tabpfn/classifier/configuration#constructor">tabpfn.Tab<wbr />PFN<wbr />Classifier</a></code> | Required | The TabPFN model to explain. |
  | <span id="get-tabpfn-explainer-data" /><code className="python-reference-parameter">data</code> | <code className="python-reference-type"><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html">pd.Data<wbr />Frame</a> \| <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a></code> | Required | The background data to use for the explainer. |
  | <span id="get-tabpfn-explainer-labels" /><code className="python-reference-parameter">labels</code> | <code className="python-reference-type"><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html">pd.Data<wbr />Frame</a> \| <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a></code> | Required | The labels for the background data. |
  | <span id="get-tabpfn-explainer-index" /><code className="python-reference-parameter">index</code> | <code className="python-reference-type">str</code> | `"k-SII"` | The explanation index. Defaults to `"k-SII"`. For Shapley values like SHAP, use `index="SV"` with `max_order=1`. See the [shapiq reference](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabularExplainer.html) for the available indices. |
  | <span id="get-tabpfn-explainer-max-order" /><code className="python-reference-parameter">max\_<wbr />order</code> | <code className="python-reference-type">int</code> | `2` | The maximum order of interactions to consider. Defaults to `2`. |
  | <span id="get-tabpfn-explainer-class-index" /><code className="python-reference-parameter">class\_<wbr />index</code> | <code className="python-reference-type">int \| None</code> | `None` | The class index of the model to explain. If not provided, the class index will be set to `1` per default for classification models. This argument is ignored for regression models. Defaults to `None`. |
  | <span id="get-tabpfn-explainer-approximator" /><code className="python-reference-parameter">approximator</code> | — | `None` | The shapiq approximator to estimate the coalition game with. Defaults to `None`, which routes to the recommended estimator: `OddSHAP` for first-order Shapley values (`index="SV"`) and `ProxySHAP` for interaction indices (see `_resolve_approximator`). Pass a shapiq `Approximator` instance or a literal string (e.g. `"auto"`) to override the routing. |
  | <span id="get-tabpfn-explainer-random-state" /><code className="python-reference-parameter">random\_<wbr />state</code> | <code className="python-reference-type">int \| None</code> | `None` | Seed forwarded to the routed `OddSHAP`/`ProxySHAP` approximator for reproducible coalition sampling. Has no effect when an explicit `approximator` is passed or the `"auto"` fallback is used. Defaults to `None`. |
  | <span id="get-tabpfn-explainer-kwargs" /><code className="python-reference-parameter">\*\*kwargs</code> | — | — | Additional keyword arguments to pass to the explainer.<br /><br />See [`shapiq.TabPFNExplainer`](https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabPFNExplainer.html) for keyword options. |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type"><a href="https://shapiq.readthedocs.io/en/latest/generated/shapiq.explainer.TabPFNExplainer.html">shapiq.Tab<wbr />PFN<wbr />Explainer</a></code> | Explainer that removes features and refits TabPFN for each coalition. |
</div>

**References**

* **\[1]** [shapiq repository](https://github.com/mmschlk/shapiq).
* **\[2]** Muschalik et al. (2024). [shapiq: Shapley Interactions for Machine Learning](https://openreview.net/forum?id=knxGmi6SJi).
* **\[3]** Rundel et al. (2024). [Interpretable Machine Learning for TabPFN](https://doi.org/10.1007/978-3-031-63797-1_23).

***

<div className="python-reference-heading">
  <h2 id="shapiq-to-shap-explanation">
    `shap.shapiq_to_shap_explanation`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/interpretability/shap.py#L27" aria-label="View source for shap.shapiq_to_shap_explanation"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Compute first-order Shapley values with a shapiq explainer for each
row in `X` and wrap them in a [`shap.Explanation`](https://shap.readthedocs.io/en/latest/generated/shap.Explanation.html) ready for use with
`shap.plots.*` and `shap.summary_plot`.

Mirrors the pattern in `examples/interpretability/shap_example.py`:
one `.explain(...)` call per row, stack the first-order arrays into an
`(n, d)` matrix, average baseline values, and pass everything to
[`shap.Explanation`](https://shap.readthedocs.io/en/latest/generated/shap.Explanation.html).

```python theme={null}
shap.shapiq_to_shap_explanation(
    explainer: Any,
    X: ArrayLike,
    *,
    budget: int,
    feature_names: list[str] | None = None,
) -> shap.Explanation
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="shapiq-to-shap-explanation-explainer" /><code className="python-reference-parameter">explainer</code> | <code className="python-reference-type">Any</code> | Required | A shapiq explainer — e.g. one returned by `get_tabpfn_imputation_explainer(..., index="SV", max_order=1)`. |
  | <span id="shapiq-to-shap-explanation-x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">Array<wbr />Like</code> | Required | `(n, d)` array of rows to explain. |
  | <span id="shapiq-to-shap-explanation-budget" /><code className="python-reference-parameter">budget</code> | <code className="python-reference-type">int</code> | Required | Number of model evaluations shapiq is allowed per row. For small `d` and exact Shapley values, pass `2**d`. |
  | <span id="shapiq-to-shap-explanation-feature-names" /><code className="python-reference-parameter">feature\_<wbr />names</code> | <code className="python-reference-type">list\[str] \| None</code> | `None` | Optional list of feature name strings (length `d`). Used by `shap.plots.*` for axis labels. |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type"><a href="https://shap.readthedocs.io/en/latest/generated/shap.Explanation.html">shap.Explanation</a></code> | Shapley values for each input sample, with `values.shape == (n, d)`. |
</div>

**Notes**

Only first-order Shapley values are wrapped. [`shap.Explanation`](https://shap.readthedocs.io/en/latest/generated/shap.Explanation.html)
doesn't represent higher-order interactions; for those, use
shapiq's native plots on the `InteractionValues` object.

Requires `shap` to be installed (`pip install shap`). It is
kept out of the `interpretability` extra by design — shapiq is
the runtime dependency, shap is opt-in for plotting.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.