shap
A unified approach to explain the output of any machine learning model.
What it is and what it does
SHAP is a model-agnostic explainability library that uses Shapley values from game theory to attribute each feature's contribution to individual model predictions. It works across tree ensembles, transformers, deep learning models, and other architectures, providing both local explanations (why a single prediction was made) and global insights (which features matter most overall).
The library provides multiple visualization methods—waterfall plots, force plots, dependence scatter plots, beeswarm plots, and bar charts—to help interpret model behavior. It includes specialized fast algorithms for tree models and approximation methods for deep learning via DeepExplainer and GradientExplainer. Installation brings 10 runtime dependencies including numpy, scipy, scikit-learn, pandas, tqdm, packaging, slicer, numba, llvmlite, and cloudpickle; GPU support is optional but requires CUDA toolkit and environment setup.
Use it for:
- Explain individual predictions in production models to stakeholders or for regulatory compliance
- Debug model behavior by identifying which features drive incorrect or unexpected predictions
- Compare feature importance across different model types to validate model selection
- Analyze transformer and NLP model outputs using coalitional Shapley rules for text-based predictions
- Visualize deep learning model decisions via DeepExplainer for image or tensor-based models
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
SHAP computes Shapley values to explain individual predictions and feature importance across any machine learning model, using game-theoretic attribution to show how each feature contributes to model output.
Yes. SHAP is actively maintained, widely used, has no known vulnerabilities, and uses permissive MIT licensing. Medium install friction is offset by comprehensive pre-built wheels and strong ecosystem support. Install if you need model explainability across any ML framework; skip only if your use case requires minimal dependencies or Python versions below 3.12.
Install
shap on PyPI
pip
pip install shapuv
uv add shappoetry
poetry add shapInstalling shap
Before you install
Medium install friction: 10 runtime dependencies including numpy, scipy, scikit-learn, pandas, numba, and llvmlite. Pre-built wheels available for Python 3.12+ across macOS, Linux, and Windows. Active maintenance with recent releases; last commit 2026-08-11.
License in practice
MIT License (permissive): you can use, modify, and distribute SHAP freely in commercial and private projects with minimal restrictions, provided you include the license notice.
Quickstart
pip install shap
import shap
X, y = shap.datasets.california()
explainer = shap.Explainer(model)
shap_values = explainer(X)
shap.plots.waterfall(shap_values[0])
Requires Python >=3.12. GPU-accelerated Tree SHAP requires CUDA toolkit and SHAP_ENABLE_CUDA=1 environment variable set at install time.
Verify before relying
- Whether GPU acceleration is automatically detected or requires explicit environment setup beyond SHAP_ENABLE_CUDA
- Performance characteristics for large datasets or high-dimensional feature spaces
- Compatibility with specific model types beyond tree ensembles and transformers mentioned in documentation
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.12) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 10 — numpy, scipy, scikit-learn, pandas, tqdm, packaging, slicer, numba, llvmlite, cloudpickle |
| Maintenance | actively maintained — 78 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 19,814,213/month — #1,054 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: shap-0.52.0-cp312-abi3-macosx_10_13_x86_64.whl; shap-0.52.0-cp312-abi3-macosx_11_0_arm64.whl; shap-0.52.0-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; shap-0.52.0-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; shap-0.52.0-cp312-abi3-musllinux_1_2_aarch64.whl; shap-0.52.0-cp312-abi3-musllinux_1_2_x86_64.whl; shap-0.52.0-cp312-abi3-win_amd64.whl; shap-0.52.0-cp314-cp314t-macosx_11_0_arm64.whl; shap-0.52.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; shap-0.52.0-cp314-cp314t-musllinux_1_2_aarch64.whl; shap-0.52.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
interpret-coreTrains interpretable machine learning models…
unclear · top 5,000 on PyPI
powershapPowershap performs feature selection by testing…
permissive · top 15,000 on PyPI
limeLime explains individual predictions from any…
permissive · top 15,000 on PyPI
interpretInterpretML provides interpretable machine…
unclear · top 15,000 on PyPI
captumCaptum provides model interpretability…
permissive · top 15,000 on PyPI
treeinterpreterDecomposes scikit-learn decision tree and…
permissive · top 15,000 on PyPI
dtreevizdtreeviz renders decision trees from…
permissive · top 15,000 on PyPI
cartoboostCartoBoost is a Rust-backed gradient boosting…
permissive · top 15,000 on PyPI
open-spielOpenSpiel provides game environments and…
permissive · top 15,000 on PyPI