A lightweight SHAP library
Project description
LightSHAP
| Package | |
| CI/CD | |
| Quality | |
| Meta |
Lightweight Python implementation of SHAP (SHapley Additive exPlanations).
📖 Documentation | 🚀 Examples | 📋 API Reference
Key Features
- Tree Models: TreeSHAP wrappers for XGBoost, LightGBM, and CatBoost via
explain_tree() - Model-Agnostic: Permutation SHAP and Kernel SHAP via
explain_any() - Visualization: Flexible plots
Highlights of the agnostic explainer:
- Exact and sampling versions of permutation SHAP and Kernel SHAP
- Sampling versions iterate until convergence, and provide standard errors
- Parallel processing via joblib
- Supports multi-output models
- Supports case weights
- Accepts numpy, pandas, and polars input, and categorical features
Some methods of the explanation object:
plot.bar(): Feature importance bar plotplot.beeswarm(): Summary beeswarm plotplot.scatter(): Dependence plotsplot.waterfall(): Waterfall plot for individual explanationsimportance(): Returns feature importance valuesset_X(): Update explanation data, e.g., to replace a numpy array with a DataFrameset_feature_names(): Set or update feature namesselect_output(): Select a specific output for multi-output modelsfilter(): Subset explanations by condition or indices- ...
Quick Start
from lightshap import explain_any, explain_tree
# For any model
explanation = explain_any(model.predict, X)
# For tree models (XGBoost, LightGBM, CatBoost)
explanation = explain_tree(model, X)
# Create plots
explanation.plot.bar() # Feature importance
explanation.plot.beeswarm() # Summary plot
explanation.plot.scatter() # Dependence plots
explanation.plot.waterfall() # Individual explanation
Gallery
Installation
# From PyPI
pip install lightshap
# With all optional dependencies
pip install lightshap[all]
# From GitHub
pip install git+https://github.com/mayer79/LightSHAP.git
Contributions are highly appreciated! When contributing, you agree that your contributions will be subject to the MIT License.
Please feel free to open an issue for bug reports, feature requests, or general discussions.
License
MIT License - see LICENSE file for details.
Acknowledgements
LightSHAP builds on top of wonderful packages like numpy, pandas, and matplotlib.
It is heavily influenced by these projects:
shap | shapley-regression | kernelshap | shapviz
References
"A Unified Approach to Interpreting Model Predictions" (S. M. Lundberg and S.-I. Lee 2017)
@incollection{lundberglee2017,
title = {A Unified Approach to Interpreting Model Predictions},
author = {Lundberg, Scott M and Lee, Su-In},
booktitle = {Advances in Neural Information Processing Systems 30},
editor = {I. Guyon and U. V. Luxburg and S. Bengio and H. Wallach and R. Fergus and S. Vishwanathan and R. Garnett},
pages = {4765--4774},
year = {2017},
publisher = {Curran Associates, Inc.},
url = {https://papers.nips.cc/paper/7062-a-unified-approach-to-interpreting-model-predictions.pdf}
}
Paper link
"Improving KernelSHAP: Practical Shapley Value Estimation via Linear Regression" (I. Covert and S.-I. Lee 2020)
@inproceedings{covertlee2020,
title={Improving KernelSHAP: Practical Shapley Value Estimation via Linear Regression},
author={Ian Covert and Su-In Lee},
booktitle={International Conference on Artificial Intelligence and Statistics},
year={2020},
url={https://proceedings.mlr.press/v130/covert21a/covert21a.pdf}
}
Paper link
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lightshap-0.1.12.tar.gz.
File metadata
- Download URL: lightshap-0.1.12.tar.gz
- Upload date:
- Size: 417.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
760def8f23ee6285fa8de9dae4b0cb3bc8a865f947d3c0d96191e9fe22791967
|
|
| MD5 |
52fc09ba6db01f385b08e901613b89e1
|
|
| BLAKE2b-256 |
c88d9624d7ef4f9a6a51faacbe929a0f5ab4c977a2a84e90a4731a515addad4e
|
Provenance
The following attestation bundles were made for lightshap-0.1.12.tar.gz:
Publisher:
release.yml on mayer79/LightSHAP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lightshap-0.1.12.tar.gz -
Subject digest:
760def8f23ee6285fa8de9dae4b0cb3bc8a865f947d3c0d96191e9fe22791967 - Sigstore transparency entry: 604941627
- Sigstore integration time:
-
Permalink:
mayer79/LightSHAP@405bcb8d2a3e7c2d5204da680d4d47c156c5ed79 -
Branch / Tag:
refs/tags/v0.1.12 - Owner: https://github.com/mayer79
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@405bcb8d2a3e7c2d5204da680d4d47c156c5ed79 -
Trigger Event:
release
-
Statement type:
File details
Details for the file lightshap-0.1.12-py3-none-any.whl.
File metadata
- Download URL: lightshap-0.1.12-py3-none-any.whl
- Upload date:
- Size: 63.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa35a2df67891146ed1aed986b3576fbd53e7626e89be8d3e7da74442a8f929a
|
|
| MD5 |
91789cb4a356e6287e4efc4e8bc2eddd
|
|
| BLAKE2b-256 |
4c3e4d80f516fa8bec23b7a1f34ed84995ecf9c95383f13a3a6b51ae11141e03
|
Provenance
The following attestation bundles were made for lightshap-0.1.12-py3-none-any.whl:
Publisher:
release.yml on mayer79/LightSHAP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lightshap-0.1.12-py3-none-any.whl -
Subject digest:
fa35a2df67891146ed1aed986b3576fbd53e7626e89be8d3e7da74442a8f929a - Sigstore transparency entry: 604941629
- Sigstore integration time:
-
Permalink:
mayer79/LightSHAP@405bcb8d2a3e7c2d5204da680d4d47c156c5ed79 -
Branch / Tag:
refs/tags/v0.1.12 - Owner: https://github.com/mayer79
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@405bcb8d2a3e7c2d5204da680d4d47c156c5ed79 -
Trigger Event:
release
-
Statement type: