Looking for usage documentation? Check out Interpretability and KV cache.
shapiq.get_tabpfn_imputation_explainer
View source TabularExplainer 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). 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.
- [1] shapiq repository.
- [2] Muschalik et al. (2024). shapiq: Shapley Interactions for Machine Learning.
- [3] Lundberg and Lee (2017). A Unified Approach to Interpreting Model Predictions.
shapiq.get_tabpfn_inf_explainer
View source TabularExplainer 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 — 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.
ValueError
If model can be introspected and does not have
PASSTHROUGH_INF enabled.
Example
shapiq.get_tabpfn_explainer
View source TabPFNExplainer (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 (which
runs budget predicts against a single fit).
- [1] shapiq repository.
- [2] Muschalik et al. (2024). shapiq: Shapley Interactions for Machine Learning.
- [3] Rundel et al. (2024). Interpretable Machine Learning for TabPFN.
shap.shapiq_to_shap_explanation
View source X and wrap them in a shap.Explanation 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.
shap.Explanation
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.