A model does not fail loudly. It keeps returning confident predictions while the world underneath it moves, and the damage only shows up later in the numbers that matter. DriftGuard is the layer that watches for that: it monitors a deployed classifier for data drift and performance loss, retrains when the model has genuinely gone stale, and promotes the replacement only if it actually wins.
The worked example is a consumer loan default classifier walking into a downturn.
- Watches the inputs. Population Stability Index and a Kolmogorov Smirnov test on every feature, categorical columns included, rolled up into one status.
- Watches the outcome. When labels arrive it scores the live batch (AUROC first) against the champion's baseline and measures how far it has fallen.
- Decides. Drift alone is a warning. A real performance drop is what earns a retrain. If labels lag, a hard input shift can stand in as the trigger.
- Retrains and gates. A challenger is fit on the pool plus the recent data, then champion and challenger are judged on a held out slice of that recent data, not the stale reference. The challenger ships only if it clears a margin.
- Keeps a registry. Every model is versioned with its metrics and a champion pointer, so you can always answer which model is serving and why it was promoted.
pip install -e ".[app,dev]"
python -m driftguard demo # train a baseline, then walk it into a downturn
python -m driftguard eval # score the drift detector on labelled scenarios
python -m driftguard serve # open the monitoring console at 127.0.0.1:8000
pytest -q # 24 testsThe demo prints the whole arc: a healthy baseline, a steady month that needs no action, then a downturn that drops the champion's AUROC past the threshold, triggers a retrain, and promotes a challenger that recovers the loss.
data.py the loan scenario, with dials for covariate and concept drift
drift/ PSI, KS and Jensen Shannon, plus the per feature report
metrics.py the model scorecard (AUROC, PR AUC, F1, Brier)
model.py the gradient boosted classifier being guarded
registry.py file backed model versioning and the champion pointer
monitor.py drift + performance -> a status and a recommended action
retrain.py fit a challenger, judge it on recent data, promote on a margin
pipeline.py the Guard: the whole watch and adapt loop in one object
api.py + web/ a live monitoring console
python -m driftguard eval grades the detector against labelled scenarios,
including quiet batches that should not trip it and a concept only batch that
moves the labels but not the inputs (which the data drift monitor is meant to
leave alone). Because it is measured against drift injected on purpose, the score
is one I trust rather than a number pulled from a single happy path.
- PSI is the primary gate because it is bounded, interpretable, and already the number risk teams read. KS is the second opinion for shape changes.
- Validate the challenger on recent data. Judging a retrain on the old reference would flatter the stale champion; the point is who wins on the world as it looks now.
- Promote on a margin, not a tie. A challenger that only matches the champion is not worth the churn of a deployment.
- No key, no service required. Everything runs locally on synthetic data you can dial, so the tests and the eval are fully reproducible.
MIT. See LICENSE.