Skip to main content

Monitor whether your model's SHAP explanations still hold as data drifts.

Project description

shiftshap

Monitor whether your model's SHAP explanations still hold as your data drifts.

shiftshap answers a question every team running a model in production eventually asks: are my model's explanations still trustworthy? Models live for months or years — they get retrained, upstream pipelines change, and feature distributions shift. When that happens, the model's reasoning quietly changes with it. The feature that drove your predictions last quarter may not be the one driving them today.

SHAP is excellent at explaining a model at a single point in time, but it has no built-in way to tell you how those explanations have changed between two points. Today people work around this by pickling explanation objects and writing their own comparison scripts, or by using data-drift tools that know nothing about SHAP's structure. shiftshap fills that gap.


Install

pip install shiftshap            # core
pip install shiftshap[plot]      # + matplotlib for the drift chart

Quickstart

If you already use SHAP, you already have everything you need. Take your SHAP values from two periods — training vs. production, or last month vs. this month — and pass them in:

import shiftshap

report = shiftshap.compare(reference_shap, current_shap)

print(report.summary())
#  2 of 5 features show HIGH explanation drift (0 medium).
#  Top driver changed from 'income' to 'balance'.
#  Overall rank stability (Spearman): 0.70.

print(report.details())          # plain-English narrative of the biggest movers
report.to_frame()                # full per-feature table
report.plot()                    # rank-drift bump chart
shiftshap.metric_definitions()   # what every metric means, in plain words

Inputs can be shap.Explanation objects, NumPy arrays, lists, or pandas DataFrames of shape (n_samples, n_features). Multi-class SHAP (3D arrays) is supported — by default classes are aggregated, or pass class_index=k to focus on one class. The two periods don't need the same number of samples.

Robust by design

shiftshap is built to survive real, messy production data. It handles NaNs (ignored with a note), zero-variance features, tiny samples (with an explicit "results unreliable" warning rather than false alarms), and multi-class outputs — and it fails with clear, actionable errors on genuinely broken input (infinities, mismatched feature counts, empty arrays) instead of cryptic stack traces.

What it tells you

For every feature, shiftshap reports:

  • Importance drift — how the mean absolute SHAP value changed between periods.
  • PSI (Population Stability Index) on the SHAP distribution — the industry-standard shift metric, with the accepted 0.2 threshold flagging significant drift.
  • Rank drift — whether your most important features reordered, plus an overall Spearman rank-stability score.
  • Severity — a high / medium / low label per feature, so the output is actionable at a glance.

And a bump chart showing how the feature-importance ranking shifted:

rank drift chart

Why it matters

An explanation that has silently drifted is worse than no explanation — it gives false confidence. In regulated settings (finance, insurance, healthcare) teams are increasingly required to show that model explanations remain valid over time. shiftshap turns that check into two lines of code.

Roadmap

v0.1 deliberately does one thing well: compare two snapshots of SHAP explanations for tabular models. Planned next:

  • Persistent explanation store for many time-points (not just two).
  • Research-grade faithfulness-under-shift metrics beyond distributional PSI.
  • Alerting hooks for monitoring pipelines.
  • Support for image and text explanations.

Contributions and issues welcome.

License

MIT

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

shiftshap-0.2.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

shiftshap-0.2.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file shiftshap-0.2.0.tar.gz.

File metadata

  • Download URL: shiftshap-0.2.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for shiftshap-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ad1d14222c5d4d2a77e7c10eb3dd528c339f3266a396824795b69761b6e67873
MD5 9cc17e7080514188f30b79149735048a
BLAKE2b-256 07642f07090d6e260c303bea1a94d484744efe51fca7bca3472fbfd44a48c752

See more details on using hashes here.

File details

Details for the file shiftshap-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: shiftshap-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for shiftshap-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7aac857e27bfc1ab20a2376a2d23af270508e66afb1a2c4454bfff10350097c2
MD5 095dc83985f540c09881e2e1adb04b09
BLAKE2b-256 d186fd9f0426b0ba2a5c44a44e90a2010e6e611f91cf9d14c11580b4f4963e93

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