https://github.com/tsitsimis/tinyshap
Python package providing a minimal implementation of the SHAP algorithm using the Kernel method
https://github.com/tsitsimis/tinyshap
explainable-ai machine-learning ml python-package shap shapely xai
Last synced: 5 months ago
JSON representation
Python package providing a minimal implementation of the SHAP algorithm using the Kernel method
- Host: GitHub
- URL: https://github.com/tsitsimis/tinyshap
- Owner: tsitsimis
- License: mit
- Created: 2023-04-09T17:48:57.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-27T10:10:56.000Z (about 3 years ago)
- Last Synced: 2025-08-29T16:58:00.353Z (10 months ago)
- Topics: explainable-ai, machine-learning, ml, python-package, shap, shapely, xai
- Language: Jupyter Notebook
- Homepage:
- Size: 177 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

A minimal implementation of the SHAP algorithm using the KernelSHAP method. In less then 100 lines of code, this repo serves as an educational resource to understand how SHAP works without all the complexities of a production-level package.
## Installation
```bash
pip install tinyshap
```
## Example usage
```python
from tinyshap import SHAPExplainer
# Train model
model = GradientBoostingRegressor()
model.fit(X_train, y_train)
# Explain predictions
explainer = SHAPExplainer(model.predict, X=X_train.mean().to_frame().T)
contributions = explainer.shap_values(X)
```
See complete [notebook](./notebooks/demo.ipynb)
## Resources
* [A Unified Approach to Interpreting Model Predictions (arXiv)](https://arxiv.org/abs/1705.07874)
* [Interpretable Machine Learning](https://christophm.github.io/interpretable-ml-book/shap.html#kernelshap)
## Licence
MIT