📈 GH Trending Explorer 🎲 Surprise me

← all repos

shap / shap

git clone https://github.com/shap/shap.git v0.54.1 · 7d ago 🔥 on GitHub Trending today

Python library that computes Shapley-value explanations for the predictions of any machine learning model.

Why you might care

Gives per-prediction and global feature attributions with a fast exact algorithm for tree ensembles like XGBoost, LightGBM, CatBoost, and scikit-learn. Use it to see which features push a model's output up or down, with built-in plots such as force and summary plots.

Categories

Alternatives

LIMEELI5InterpretMLCaptum
+1
stars, 24h · #13,886
+~7
stars, 7 days · #14,220
+82
stars, 30 days · #8,209
26k
★ total · +0% this week
3.8k
forks · 998 open issues

Star history (as recorded here)

2026-10-20 · 25,823 ★ 2026-10-23 · 25,826 ★
LanguageJupyter Notebook
LicenseMIT
Created2016-11-22 (9y ago)
Last push2d ago
Watchers246
OwnerOrganization

Seen on GitHub Trending

  • 2026-10-23 — #13 monthly in jupyter-notebook · +80 ★
  • 2026-10-22 — #13 monthly in jupyter-notebook · +82 ★
  • 2026-10-21 — #8 monthly in jupyter-notebook · +85 ★
  • 2026-10-20 — #8 monthly in jupyter-notebook · +88 ★

GitHub topics

Links

README excerpt
---
**SHAP (SHapley Additive exPlanations)** is a game theoretic approach to explain the output of any machine learning model. It connects optimal credit allocation with local explanations using the classic Shapley values from game theory and their related extensions (see papers for details and citations).
## Install
SHAP can be installed from either PyPI or conda-forge:
pip install shap
 or 
conda install -c conda-forge shap
### GPU support
To enable GPU-accelerated Tree SHAP (`GPUTreeExplainer`), install the `cuda` extra:
pip install shap[cuda]
This requires the CUDA toolkit to be installed on your system.
## Supported versions
SHAP follows SPEC 0 for minimum supported dependency versions. We test against the versions specified there and may not fix bugs for older versions.
## Contributing
We welcome contributions highly. Feel free to file an issue. Before opening a PR make sure you've read our CONTRIBUTING.md guideline.
## Tree ensemble example (XGBoost/LightGBM/CatBoost/scikit-learn/pyspark models)
While SHAP can explain the output of any machine learning model, we have developed a high-speed exact algorithm for tree ensemble methods (see our Nature MI paper). Fast C++ implementations are supported for *XGBoost*, *LightGBM*, *CatBoost*, *scikit-learn* and *pyspark* tree models:
 [code] 
The above explanation shows features each contributing to push the model output from the base value (the average model output over the training dataset we passed) to the model output. Features pushing the prediction higher are shown in red, those pushing the prediction lower are in blue. Another way to visualize the same explanation is to use a force plot (these are introduced in our Nature BME paper):
 [code] 
If we take many force plot explanations such as the one shown above, rotate them 90 degrees, and then stack them horizontally, we can see explanations for an entire dataset (in the notebook this plot is interactive):
 [code] 
To understand how a single feature effects the output of the model we can plot the SHAP value of that feature vs. the value of the feature for all the examples in a dataset. Since SHAP values represent a feature's responsibility for a change in the model output, the plot below represents the change in predicted house price as the latitude changes. Vertical dispersion at a single value of latitude represents interaction effects with other features. To help reveal these interactions we can color by another feature. If we pass the whole explanation tensor to the `color` argument the scatter plot will pick the best feature to color by. In this case it picks longitude.
 [code] 
To get an overview of which features are most important for a model we can plot the SHAP values of every feature for every sample. The plot below sorts features by the sum of SHAP value magnitudes over all samples, and uses SHAP values to show the distribution of the impacts each feature has on the model output. The color represents the feature value (red high, b

Blurb generated by claude-haiku-5-5 today. Star deltas marked ~ are extrapolated from partial history.