A monitoring tool for SHAP values in machine learning models.
Project description
shap-monitor
Production ML explainability toolkit for monitoring SHAP values over time. Track how your model's explanations evolve, detect explanation drift, and maintain interpretability at scale.
Overview
Most SHAP tooling focuses on development and analysis. shap-monitor bridges the gap for production monitoring, helping ML teams understand when and how their models' explanations change over time, compare reasoning across model versions, and detect shifts in feature importance patterns.
Key Features
- Explanation Logging: Automatically log SHAP values for production predictions with configurable sampling
- Flexible Storage: Parquet-based storage with pluggable backend support
- Multiple Explainers: Works with TreeExplainer, LinearExplainer, and other SHAP explainers
Installation
This project uses Poetry for dependency management. Ensure you have Python 3.11 or higher installed.
# Clone the repository
git clone https://github.com/yourusername/shap-monitor.git
cd shap-monitor
# Install with Poetry
poetry install
# Or install for development with all dev dependencies
poetry install --with dev
For production use, install directly from the package (when published):
pip install shap-monitor
Quick Start
Here's a minimal example to get started with shap-monitor:
from shapmonitor import SHAPMonitor
import shap
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
# Train a simple model
X, y = make_classification(n_samples=1000, n_features=10, random_state=42)
model = RandomForestClassifier(random_state=42)
model.fit(X, y)
# Create SHAP explainer
explainer = shap.TreeExplainer(model)
# Initialize the monitor
monitor = SHAPMonitor(
explainer=explainer,
data_dir="./shap_logs",
sample_rate=0.1, # Log 10% of predictions
model_version="v1.0",
feature_names=[f"feature_{i}" for i in range(10)]
)
# In your prediction loop
predictions = model.predict(X[:100])
monitor.log(X[:100], predictions)
# Or compute SHAP values directly
explanation = monitor.compute(X[:10])
The monitor will automatically:
- Sample predictions based on the configured
sample_rate - Compute SHAP values for sampled predictions
- Store explanations to Parquet files in the specified
data_dir
Current Status
This project is in early development (v0.1). The core functionality is being actively developed.
Roadmap
- v0.1 (Current): Core synchronous monitoring, Parquet storage
- v0.2 (Planned): Drift detection, asynchronous processing, MLflow integration
- v0.3+ (Future): Dashboard/visualization, additional framework integrations, advanced alerting
Development
Prerequisites
- Python 3.11 or higher
- Poetry for dependency management
Setup
# Install development dependencies
make setup
# Install pre-commit hooks
poetry run pre-commit install
# Run tests
make test
# Format code
make lint
Code Quality
This project uses:
- black for code formatting (line length: 100)
- ruff for linting
- pytest for testing
- pre-commit for automated checks
Contributing
Contributions are welcome! This project is in early development, and we're building the foundation for production ML explainability monitoring.
How to Contribute
- Report Issues: Found a bug or have a feature request? Open an issue on GitHub
- Submit Pull Requests:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Make your changes with tests
- Ensure code passes all checks (
poetry run pytest && poetry run black . && poetry run ruff check .) - Submit a pull request
Development Guidelines
- Write tests for new features
- Follow existing code style (enforced by black and ruff)
- Use type hints for all function signatures
- Add docstrings for public APIs
- Keep commits focused and write clear commit messages
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Acknowledgments
Built on top of the excellent SHAP library by Scott Lundberg and the SHAP community.
Project details
Release history Release notifications | RSS feed
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 shap_monitor-0.0.1.tar.gz.
File metadata
- Download URL: shap_monitor-0.0.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c19390a12c8ffa69a824cd81d1afb13aa171a990906608cc0237aeee064a62f
|
|
| MD5 |
5ef46044e6c067f6b0a7c59d2722eea8
|
|
| BLAKE2b-256 |
b5455b1dfe265aa13d76071e223052807fcc78da093e2c72b00f9aa095b682bd
|
Provenance
The following attestation bundles were made for shap_monitor-0.0.1.tar.gz:
Publisher:
publish.yml on ab93/shap-monitor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shap_monitor-0.0.1.tar.gz -
Subject digest:
6c19390a12c8ffa69a824cd81d1afb13aa171a990906608cc0237aeee064a62f - Sigstore transparency entry: 780856453
- Sigstore integration time:
-
Permalink:
ab93/shap-monitor@4b36c6752362e251e915706033e6cf231d0e0fc8 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ab93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b36c6752362e251e915706033e6cf231d0e0fc8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file shap_monitor-0.0.1-py3-none-any.whl.
File metadata
- Download URL: shap_monitor-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.1 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 |
646cb72f841504f274e703d710d481ec5fbc2158e168869d67a179f5eab2fcac
|
|
| MD5 |
8a7b70318dc75ad2069ca750ea1e4696
|
|
| BLAKE2b-256 |
cc44a2e84aae2e7b18bc5ad713c861ea1d2f6d0677e44df02f4e72a02e1f9d40
|
Provenance
The following attestation bundles were made for shap_monitor-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on ab93/shap-monitor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shap_monitor-0.0.1-py3-none-any.whl -
Subject digest:
646cb72f841504f274e703d710d481ec5fbc2158e168869d67a179f5eab2fcac - Sigstore transparency entry: 780856454
- Sigstore integration time:
-
Permalink:
ab93/shap-monitor@4b36c6752362e251e915706033e6cf231d0e0fc8 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ab93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b36c6752362e251e915706033e6cf231d0e0fc8 -
Trigger Event:
release
-
Statement type: