Skip to main content

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.

Work in Progress Python License codecov

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

You can install shap-monitor via pip:

pip install shap-monitor

Installation from Source

This project uses Poetry for dependency management. Ensure you have Python 3.10 or higher installed.

# Clone the repository
git clone https://github.com/ab93/shap-monitor.git
cd shap-monitor

# Install with Poetry
poetry install

# Or install for development with all dev dependencies
poetry install --with dev

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_batch(X[:100], predictions)

# Or compute SHAP values directly
explanation = monitor.compute(X[:10])

The monitor will automatically:

  1. Sample predictions based on the configured sample_rate
  2. Compute SHAP values for sampled predictions
  3. 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

  1. Report Issues: Found a bug or have a feature request? Open an issue on GitHub
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shap_monitor-0.0.10.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

shap_monitor-0.0.10-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file shap_monitor-0.0.10.tar.gz.

File metadata

  • Download URL: shap_monitor-0.0.10.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shap_monitor-0.0.10.tar.gz
Algorithm Hash digest
SHA256 7a14161cc9583dd7f994c16eb6f9bc58b3fbf0b6b6a3b4c9fd5c84b9d05e70bb
MD5 067f81075d7ac641b0f4ac69542a58db
BLAKE2b-256 ee111febe578b3b9d1e6459b15ae6fa59bfe5055e4f39539318e7afb623c94f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for shap_monitor-0.0.10.tar.gz:

Publisher: publish.yml on ab93/shap-monitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shap_monitor-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: shap_monitor-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shap_monitor-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6bc0b74a6d688d9cface2656c363358e38c87d46425314183d088ebe2ca9a219
MD5 a8cd4cd392924a3225017ac1026e659b
BLAKE2b-256 de6bfec333710b1cb67da142f2bad968b99fc4e1ee4956461c9cc41a375fca8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for shap_monitor-0.0.10-py3-none-any.whl:

Publisher: publish.yml on ab93/shap-monitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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