Skip to main content

Quantify SHAP feature importance stability across structural breaks in time-series data

Project description

regime-shap

Quantify SHAP feature importance stability across structural breaks in time-series data.

CI PyPI License: MIT Python 3.10+ Docs

Install with pip install regime-shap. The package follows Semantic Versioning; during the 0.x series the public API may still change.

Documentation: https://faithcodes-lab.github.io/regime-shap/

regime-shap extends SHAP feature importance analysis to time-series with structural breaks. Given a pre-trained tree model, a feature matrix, and a set of regimes, it quantifies how the model's feature importance rankings change across regimes, surfacing instability that may matter for trustworthy interpretation.

Development status

Built so far:

  • breaks: turn regime specifications into per-row regime labels (plus optional break detection).
  • compare: per-regime SHAP feature importance and rankings, with small-sample flagging.
  • stability: pairwise Spearman stability matrix, Akoglu (2018) bands, and bootstrap confidence intervals.
  • plots: global and per-regime importance figures, and the banded stability heatmap.
  • report: self-contained HTML report plus dict and CSV export.
  • RegimeSHAPAnalyzer: a single high-level entry point that ties the modules together.

Usage

from regime_shap import RegimeSHAPAnalyzer

# model is a fitted tree model, X is the feature matrix, regimes is one label per row
analyzer = RegimeSHAPAnalyzer(model, X, regimes)

analyzer.stability_matrix()      # regime-by-regime Spearman correlation of importance rankings
analyzer.stability_classified()  # each regime pair with its Akoglu (2018) stability band
analyzer.plot_stability()        # the banded stability heatmap
analyzer.to_html(title="...")    # a self-contained report of every result table

The building-block functions in regime_shap.breaks, regime_shap.compare, and regime_shap.stability are also available directly if you want finer control.

Supported models

regime-shap currently supports tree-based models (for example XGBoost, LightGBM, and scikit-learn tree ensembles) through SHAP's TreeExplainer. This is a deliberate choice: TreeExplainer computes exact SHAP values quickly, which is what makes the bootstrap confidence intervals feasible, since they recompute SHAP up to a thousand times per regime.

The stability methodology itself is model-agnostic. The comparison, stability, plotting, and report steps operate on SHAP values alone and never inspect the model, so only the SHAP computation is tree-specific.

Support for other model types through pluggable explainers (for example KernelExplainer for arbitrary models, or LinearExplainer for linear ones) is a possible future extension, tracked in issue #8. The honest caveat is that the bootstrap confidence intervals become expensive and approximate for non-tree models, because general explainers are slower and introduce sampling variance.

Installation

pip install regime-shap

For development, install from source:

git clone https://github.com/faithcodes-lab/regime-shap.git
cd regime-shap
pip install -e ".[dev]"

Origin

This package generalises a SHAP stability methodology, first developed for analysing UK economic regimes (the Global Financial Crisis, Brexit, and COVID-19), into a standalone, domain-agnostic tool. Its examples span finance and energy as well as macroeconomics.

If you use regime-shap in research, please cite:

@software{olan_george_regime_shap,
  author = {Olan-George, Faith},
  title = {regime-shap: Quantifying SHAP Feature Importance Stability Across Structural Breaks},
  year = {2026},
  url = {https://github.com/faithcodes-lab/regime-shap},
}

Licence

MIT, see LICENSE for details.

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

regime_shap-0.1.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

regime_shap-0.1.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file regime_shap-0.1.0.tar.gz.

File metadata

  • Download URL: regime_shap-0.1.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for regime_shap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b6aa490a79289ba1a75045d9c8dc7ac57e32ddf1e70c3407e28648d39713c193
MD5 e214d06defd5d2dec97373d71114a472
BLAKE2b-256 c5780a9870fcf5aae5939ac71c6bd0a1e90a3e2aeff71fc0341f9478e17f4ce3

See more details on using hashes here.

Provenance

The following attestation bundles were made for regime_shap-0.1.0.tar.gz:

Publisher: publish.yml on faithcodes-lab/regime-shap

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

File details

Details for the file regime_shap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: regime_shap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for regime_shap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5db497fbeeae81b31b3787a96f8a3e43db4959a2db52ff68944ec10dd7f8250
MD5 f7bf9c5ef2ed16b098b5128a1ec5caf8
BLAKE2b-256 e82befdbe582f404cc67f8053e4e63bbe28fd702c06c3b3f63ddc7899721b9b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for regime_shap-0.1.0-py3-none-any.whl:

Publisher: publish.yml on faithcodes-lab/regime-shap

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