Sub topic 15
Responding to drift: investigate, retrain or roll back
An alert tells you that something changed. It does not tell you what to do. This chapter covers the steps between a drift alert and a fix, and how to pick among four responses: ignore, investigate, retrain, or roll back.
I assume you already have the following from earlier chapters:
- Drift scores (KS, chi-square, PSI) computed against a reference window.
- Data quality checks.
- Alert thresholds.
- A way to compute performance once labels arrive.
Why retraining is not the default
Retraining on a drift alert is tempting because it is automatic and feels safe. It fails in several common ways:
- The input is broken. If an upstream job started sending nulls or a changed unit, retraining teaches the model the broken data. The correct fix is in the pipeline.
- The drift is harmless. A feature can shift without affecting predictions. Retraining then adds cost and risk for no gain.
- The new model is not better. A retrained model can be worse than the current one, especially on a short or unlabeled window.
- The cause is a bad release. If the problem began at a deployment, the fastest repair is to return to the previous version.
So the response is a short triage, done in a fixed order.
Step 1: Confirm the alert is real
Before spending time, rule out the cheap explanations.
- Check the sample size. With thousands of rows, a KS test flags tiny shifts with very small p-values. Look at the effect size (KS statistic, PSI) and not only the p-value.
- Check the window. A weekend, a holiday or a marketing campaign can move distributions in a predictable way. Compare against the same weekday or the same season if your baseline allows it.
- Check persistence. Did the score cross the threshold once, or on several consecutive windows? A single spike is often noise. Many teams require two or three consecutive breaches before paging someone.
- Check the monitor itself. A bug in the monitoring job, such as a changed query or a wrong reference table, produces drift that is not in the data.
Step 2: Rule out broken inputs
Look at data quality results next. Typical findings:
- A column that is now mostly null, or filled with a default value such as
-1or0. - A categorical feature with a new spelling or a new category that the encoder maps to "unknown".
- A unit or scale change, for example prices in cents instead of dollars.
- A late or duplicated upstream feed, which shifts timestamp-based features.
If you find one of these, the action is to fix the source or add a guard, then re-score affected predictions if they matter. Do not retrain.
Step 3: Locate the change
If the inputs are valid, narrow down where the drift sits:
- Which features? Rank features by drift score. One feature with a large score suggests a local cause. Many moderate scores suggest a population shift.
- Which segments? Slice by region, device, customer type or product. Drift in one segment can be hidden in the global average.
- When did it start? Plot the score over time and mark deployments, upstream schema changes, new data sources and business events. An abrupt start usually points to a change in software or data. A slow ramp points to a change in the world.
- Do predictions move too? If feature drift does not change the prediction distribution, the model may be insensitive to it. If predictions moved, the effect is real and worth measuring.
The multivariate domain classifier from the earlier chapter helps here. Its feature importances show which columns separate the reference from the current window.
Step 4: Measure the impact
Drift matters only if it hurts decisions. Use the best evidence available:
- Labels have arrived: compute the real metric on the recent window and compare with the baseline, with a confidence interval. A drop larger than normal week-to-week variation is confirmed degradation.
- Labels are late or missing: use proxy signals. These include estimated performance from methods that reweight past labeled data, business metrics such as conversion or complaint rate, and agreement with a simpler baseline model.
- No evidence either way: treat the drift as unresolved. Keep monitoring, and prioritize collecting labels for a sample of the drifted segment.
Step 5: Choose the response
| Situation | Response | Reason |
|---|---|---|
| Data quality check fails | Fix the pipeline | The model is fine, the input is not |
| Drift, no performance loss, stable proxies | Ignore and keep watching | Retraining adds risk without benefit |
| Performance drop right after a model or feature release | Roll back | Fastest way to restore known behavior |
| Confirmed drop, world has changed, fresh labels available | Retrain | The old relationship no longer holds |
| Drift in a key feature, labels not yet available | Investigate, label a sample | Impact is unknown |
| Confirmed drop, no usable fresh labels | Roll back or add a fallback rule | A retrain cannot be validated |
Retraining safely
- Choose the training window on purpose. A longer window gives more data but includes old behavior. A short window tracks change but may be small or biased. For sudden concept drift, weight recent data more heavily or drop data from before the change.
- Use only labels you trust. Labels can be biased by the model itself, for example loan outcomes that exist only for approved applicants.
- Evaluate on recent data. Hold out the newest period as the test set, not a random split. A random split hides the very shift you are trying to handle.
- Compare against the current model. Score the champion and the candidate on the same recent labeled data. Promote the candidate only if it wins by a margin larger than noise.
- Roll out gradually. Run the candidate in shadow mode, then as a canary on a small share of traffic, watching the same monitors.
- Reset the reference. After promotion, update the reference window to the new training data, or the drift alert will fire forever.
Rolling back safely
Rollback only works if you prepared for it:
- Keep the previous model artifact and its feature code versioned and deployable.
- Check that the old model still accepts the current feature schema. A rollback fails if features were renamed or removed.
- Remember that the previous model also suffers from any drift in the world. Rollback fixes a bad release, not a changed environment.
- Record why you rolled back, so the same release is not repeated without a fix.
A triage function
The following function encodes the order above. It is a starting point for a runbook, not a replacement for judgment. It needs Python 3.8 or later and no extra packages.
from dataclasses import dataclass
from typing import Optional
@dataclass
class Signals:
data_quality_failed: bool
drift_confirmed: bool # persisted over several windows
prediction_drift: bool
labels_available: bool
metric_drop: Optional[float] # relative drop vs baseline, e.g. 0.08
drop_threshold: float # drop considered meaningful
recent_release: bool # model or feature release in the onset window
fresh_labels_enough: bool # enough recent labels to train and validate
def decide(s: Signals) -> str:
if s.data_quality_failed:
return "fix_pipeline"
if not s.drift_confirmed and not (s.metric_drop and s.metric_drop >= s.drop_threshold):
return "ignore_and_watch"
degraded = (
s.labels_available
and s.metric_drop is not None
and s.metric_drop >= s.drop_threshold
)
if degraded:
if s.recent_release:
return "roll_back"
if s.fresh_labels_enough:
return "retrain"
return "roll_back_or_fallback"
if s.labels_available:
return "ignore_and_watch" # labels show no meaningful drop
if s.prediction_drift:
return "investigate_and_label_sample"
return "ignore_and_watch"
if __name__ == "__main__":
case = Signals(
data_quality_failed=False,
drift_confirmed=True,
prediction_drift=True,
labels_available=True,
metric_drop=0.09,
drop_threshold=0.05,
recent_release=False,
fresh_labels_enough=True,
)
print(decide(case)) # retrainThe decision flow
After the response
Close the loop, or the same incident returns:
- Write a short incident note: onset time, cause, evidence, action and result.
- Update thresholds if the alert was a false alarm, or add a new check if a failure slipped past the monitors.
- Reset the reference data after a retrain.
- Confirm that the drift score and the performance metric return to normal after the action.
Exercise
Your monitor reports PSI = 0.31 on the feature session_length for three consecutive days. Data quality checks pass. Labels arrive after 30 days, so none exist for the drifted period. Predictions have shifted slightly upward. A new app version shipped on the day the drift began, and the model itself was not changed. What do you do first, and what would make you retrain?
Show answer
Investigate before changing the model. The app release is the likely cause, so check whether it changed how session_length is measured (for example, a new timer or a different unit). If so, fix or correct the feature at the source, and do not retrain. Because labels are delayed, estimate impact with proxy signals and label a sample of recent cases. Retrain only if the labeled sample shows a real performance drop and the feature is measured correctly, using recent validated labels and comparing the candidate with the current model before a canary rollout.