Skip to main content

Logo

LightSHAP

Package PyPI - Python Version PyPI - Version License - MIT GitHub release Development Status
CI/CD CI - Test GitHub release
Quality Code style: Ruff codecov GitHub issues
Meta Hatch project GitHub contributors

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:

  1. Exact and sampling versions of permutation SHAP and Kernel SHAP
  2. Sampling versions iterate until convergence, and provide standard errors
  3. Parallel processing via joblib
  4. Supports multi-output models
  5. Supports case weights
  6. Accepts numpy, pandas, and polars input, and categorical features

Some methods of the explanation object:

  • plot.bar(): Feature importance bar plot
  • plot.beeswarm(): Summary beeswarm plot
  • plot.scatter(): Dependence plots
  • plot.waterfall(): Waterfall plot for individual explanations
  • importance(): Returns feature importance values
  • set_X(): Update explanation data, e.g., to replace a numpy array with a DataFrame
  • set_feature_names(): Set or update feature names
  • select_output(): Select a specific output for multi-output models
  • filter(): Subset explanations by condition or indices
  • ...

Usage

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)
# explanation.set_X(df)  # Optional: replace array with DataFrame for better plots

# Create plots
explanation.plot.bar()       # Feature importance
explanation.plot.beeswarm()  # Summary plot
explanation.plot.scatter()   # Dependence plots
explanation.plot.waterfall() # Individual explanation

SHAP importance

SHAP summary

SHAP dependence

SHAP waterfall

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

Metadata

Release files for lightshap 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lightshap 0.1.13
File Size Uploaded
lightshap-0.1.13.tar.gz 417.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lightshap 0.1.13
File Interpreter ABI Platform
lightshap-0.1.13-py3-none-any.whl Python 3 none any Details

Total release size: 481.3 kB

Release files / lightshap-0.1.13.tar.gz

Download URL lightshap-0.1.13.tar.gz
Size 417.5 kB
Tags Source
SHA-256 checksum
How to use checksums
df063963fbf8bafeac3fe4f89adec3b91f530300236544211439b32dc1ceac48
BLAKE2b-256 checksum
How to use checksums
c54c8206559ce9d98a42139ca5c4c34b5484e6d5e1050c1a32ea738b56da5398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release files / lightshap-0.1.13-py3-none-any.whl

Download URL lightshap-0.1.13-py3-none-any.whl
Size 63.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe2ec580aeb949ac589e60c8c560a1cd42166f88ca48f2f2e496dba3d0d9b16a
BLAKE2b-256 checksum
How to use checksums
db5b2d5b9242634cbc69fe4afe4d6ba143aa645750b99bba74a12662698537d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.13 This release

2 release files

0.1.12

2 release files

0.1.10

1 release file

0.1.9

2 release files

0.1.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page