Skip to main content

A lightweight SHAP library

Project description

Logo

LightSHAP

Package PyPI - Python 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

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

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

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

lightshap-0.1.8.tar.gz (426.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lightshap-0.1.8-py3-none-any.whl (63.9 kB view details)

Uploaded Python 3

File details

Details for the file lightshap-0.1.8.tar.gz.

File metadata

  • Download URL: lightshap-0.1.8.tar.gz
  • Upload date:
  • Size: 426.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for lightshap-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b7acc8c2fdd4868d77fb1742dee1c0a3574394161a4867de0c048fd8f0eddace
MD5 230053c854cb45ff2e7f40b683bb9608
BLAKE2b-256 b4cd7fbaf6fc2c1d71578a335a96b296344d7df4bf7cd706e785bd369ee8b164

See more details on using hashes here.

File details

Details for the file lightshap-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: lightshap-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 63.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for lightshap-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0f9e714f5121463ee6b0e28814377e1361b23da07cf20e246ad1591bf4137381
MD5 06b0fbb1dc47b91cd1ec54afc706d504
BLAKE2b-256 c0a15d6927d02511f5ea21772140c2052ad41a25f03b2991d117a71035f50a6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page