Sub topic 12
When drift matters and when it does not
This chapter assumes you can run the KS test, chi-square test and PSI from the earlier chapters. It also assumes you know the difference between covariate shift, label shift and concept drift. The goal here is to decide what to do with a drift signal. A drift score tells you the data changed. It does not tell you the model got worse.
Drift is a symptom, not a verdict
A drift test compares two samples of one feature. It answers "do these windows look different?" The question you care about is "is the model's output still good enough?" These questions overlap but are not the same.
Four combinations can occur:
| Drift signal | Performance | What it usually means |
|---|---|---|
| Drift | Performance drops | A real problem. Investigate, then retrain or roll back. |
| Drift | Performance stable | Benign drift. The model is robust to this change, or the feature matters little. |
| No drift | Performance drops | Concept drift, a label change, or a bug the tests do not see. |
| No drift | Performance stable | Healthy. |
The third row is the one that surprises people. Concept drift changes the relationship between inputs and labels. The inputs can look identical while the right answer changes. Input-only drift tests cannot see this. Only performance monitoring can.
Why drift often does not matter
The feature has low importance
A model may barely use the feature that drifted. If a feature has near-zero importance, its shift has near-zero effect on predictions. Weigh each drift score by how much the model relies on that feature. Permutation importance or SHAP values, computed at training time, give you those weights.
The shift stays inside the region the model knows
Suppose a model trained on ages 18 to 80 sees the average age move from 40 to 44. Every new value still falls in a well-covered region of the training data. The model has seen examples there, so its predictions remain reliable. Compare that with a shift where new values fall outside the training range. There the model extrapolates, and errors usually grow.
The decision boundary is far away
A model that approves a loan when a score exceeds 0.5 only changes decisions near 0.5. If drift moves most scores from 0.1 to 0.15, no decisions change. Check whether the drift moves enough examples across the decision boundary.
The sample is large
With 5,000 or more rows per window, tests detect differences too small to matter. The KS example from earlier chapters shows this: a mean shift of 0.3 standard deviations gives a very small p-value. A tiny p-value means you are confident the windows differ. It does not mean the difference is large. Always read an effect size alongside the p-value.
import numpy as np
from scipy.stats import ks_2samp
rng = np.random.default_rng(1)
reference = rng.normal(0.0, 1.0, size=200_000)
current = rng.normal(0.02, 1.0, size=200_000) # a tiny shift
result = ks_2samp(reference, current)
print(f"KS statistic={result.statistic:.4f}, p-value={result.pvalue:.2e}")With 200,000 rows per window, the p-value is far below 0.05 even though the shift is only 0.02 standard deviations. The KS statistic stays near 0.01. Treat the statistic (the distance) as the effect size, and use the p-value only as a sanity check.
Why drift sometimes matters a lot
The important feature moved
Drift in a feature that dominates the model's predictions is a strong warning. Even a modest shift in such a feature can move many predictions.
The shift reaches new regions
If current data contains values or categories the model never saw, predictions there are unreliable. Check for unseen categories and out-of-range values. These are cheap to detect and often more informative than a distribution test.
Prediction drift accompanies input drift
When input drift and prediction drift appear together, the model is reacting to the change. The model output is what downstream systems consume, so a shifted score distribution has direct business effects. A threshold-based rule, such as a fraud flag rate, may jump even if accuracy is unknown.
The relationship changed
Concept drift is the worst case because inputs may look normal. A fraud pattern that changes, or a customer behavior that shifts after a price change, breaks the learned mapping. Only labels or good proxies reveal it.
Turn drift into impact estimates
Instead of asking whether a feature drifted, ask how much the model's behavior changed. Two practical approaches follow.
Weight drift by importance
Compute a drift score per feature, then combine it with feature importance. A simple report ranks features by importance * drift_score. The top items deserve attention first.
import numpy as np
import pandas as pd
def psi(reference, current, bins=10, eps=1e-6):
edges = np.quantile(reference, np.linspace(0, 1, bins + 1))
edges[0], edges[-1] = -np.inf, np.inf
edges = np.unique(edges)
ref_pct = np.histogram(reference, bins=edges)[0] / len(reference)
cur_pct = np.histogram(current, bins=edges)[0] / len(current)
ref_pct = np.clip(ref_pct, eps, None)
cur_pct = np.clip(cur_pct, eps, None)
return float(np.sum((cur_pct - ref_pct) * np.log(cur_pct / ref_pct)))
rng = np.random.default_rng(2)
reference = pd.DataFrame({
"income": rng.normal(50, 10, 5000),
"tenure": rng.normal(5, 2, 5000),
"noise": rng.normal(0, 1, 5000),
})
current = reference.copy()
current["income"] = rng.normal(55, 10, 5000)
current["noise"] = rng.normal(0.5, 1, 5000)
importance = {"income": 0.6, "tenure": 0.3, "noise": 0.01}
rows = []
for col in reference.columns:
score = psi(reference[col].to_numpy(), current[col].to_numpy())
rows.append((col, score, importance[col], score * importance[col]))
report = pd.DataFrame(rows, columns=["feature", "psi", "importance", "weighted"])
print(report.sort_values("weighted", ascending=False).to_string(index=False))In this output, noise has a PSI similar to income, but its weighted score is tiny because the model barely uses it. The weighting separates the alarming shift from the harmless one.
Replay the model on current data
You can also measure the effect on predictions directly, without labels. Score the current window and compare the prediction distribution with the reference window. Then count how many decisions flipped across the threshold. This is a direct measure of impact, and it works even when labels are late.
Common mistakes
- Retraining on every alert. If the cause is a broken pipeline, retraining teaches the model the broken data. Check data quality first.
- Treating a p-value as importance. Large samples make small shifts significant. Use distance measures and thresholds on effect size.
- Ignoring seasonality. A weekly or yearly cycle looks like drift if the reference window covers a different phase. Compare against the same phase of the cycle.
- Testing many features without correction. With 200 features and a 0.05 threshold, about 10 will fire by chance. Use stricter thresholds or alert on the share of drifted features.
- Assuming no drift means no problem. Concept drift and label changes need performance or proxy monitoring.
A practical triage routine
- Check data quality. Missing values, schema changes and unit changes are the most common cause of sudden drift.
- Look at which features drifted and how important they are.
- Check for unseen categories and out-of-range values.
- Look at prediction drift and the share of decisions that changed.
- Check performance if labels have arrived, or a proxy metric if they have not.
- Choose a response: ignore and log, investigate further, roll back a recent release, or retrain.
Steps 1 and 2 take minutes and resolve most alerts. Steps 5 and 6 need more information and more care.
Exercise
A model's input feature session_length shows a PSI of 0.4 against the reference window. The model's feature importance for session_length is 0.01, prediction scores have not shifted, and the labeled accuracy from the last two weeks is unchanged. What do you do, and why?
Show answer
Log the alert and do not retrain. The feature barely influences predictions (importance 0.01), prediction drift is absent and measured performance is stable, so this is benign drift. Record the decision and consider lowering the alert priority or raising the threshold for this feature to reduce future noise. Keep watching it in case the model is later retrained with a higher reliance on this feature.
Exercise
Accuracy on newly labeled data falls by 8 points, but no feature shows drift in KS, chi-square or PSI tests. Which type of change is most likely, and why can the drift tests not detect it?
Show answer
Concept drift is the most likely cause. The relationship between the inputs and the label changed, while the input distributions stayed the same. Drift tests compare only input distributions, so they see no change. Performance monitoring with labels caught it. You would investigate recent changes in the labeling process or the real-world behavior, and then likely retrain on recent labeled data.