fastshap

Train amortized neural explainers that estimate Shapley values for tabular and image models.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill fastshap-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastshap
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/SHAP/amortized-shap
Command: npx skills add https://github.com/zjunlp/Mechanist --skill fastshap-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, numpy, scikit-learn, fastshap, and includes scripts (resource) components.

What problem does it solve? Computing Shapley values with methods like KernelSHAP requires running a separate estimation procedure for every sample, which is too slow for real-time or large-batch model explainability. This Skill trains an amortized FastSHAP explainer that produces Shapley value estimates in a single forward pass. ## Core Features & Use Cases - Amortized Explainer Training: Train a PyTorch neural network (MLP for tabular, UNet for images) with a KernelSHAP-inspired objective to output Shapley values directly. - Surrogate Model Support: Train surrogate models that accept masked features, with marginal, baseline, and image imputation strategies for tabular and image data. - Efficiency Normalization: Apply additive or multiplicative normalization so Shapley estimates satisfy the efficiency axiom. - Use Case: You have a trained LightGBM model on census data and need per-feature attribution for thousands of predictions. Train a surrogate and FastSHAP explainer once, then generate all explanations with single forward passes instead of running KernelSHAP per sample. ## Quick Start Train a FastSHAP explainer on my tabular dataset and generate Shapley value explanations for the test set.

Frequently Asked Questions about fastshap

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train a FastSHAP explainer for tabular data?

Train a surrogate MLP that accepts masked features using Surrogate.train with a MarginalImputer, then train the explainer via FastSHAP.train with num_samples coalitions per batch. After training, call fastshap.shap_values(X_test) to get explanations in one forward pass.

What is the difference between FastSHAP and KernelSHAP?

KernelSHAP estimates Shapley values separately for each sample through repeated model evaluations, while FastSHAP trains a neural network to amortize this cost. Once trained, FastSHAP produces explanations in a single forward pass, making it suitable for real-time or batch explanation.

Does FastSHAP support image models like ResNet?

Yes, FastSHAP supports image data through ImageSurrogate and BaselineImageImputer, which mask superpixels of a fixed size. The explainer is typically a UNet that outputs per-superpixel Shapley values for each class.

Which imputer should I use for tabular Shapley values?

MarginalImputer is recommended for tabular data because it replaces masked features with samples from the training distribution, staying faithful to the original model. BaselineImputer is faster but uses a fixed reference value and is less statistically principled.

Why do my FastSHAP values not sum to the model output?

Shapley values satisfy the efficiency axiom only when normalization is applied. Pass normalization='additive' to FastSHAP so predictions are adjusted such that their sum equals f(x) minus the null prediction.

Can FastSHAP work without training a separate surrogate model?

Yes, the single-model approach trains the predictive model itself to handle missing features, removing the need for a surrogate. This requires retraining the original model, as shown in the CIFAR-10 single model notebook.