Foundations to Frontier
Tests
N. MLOps and AI Systems Engineering › N4 Monitoring and Maintenance

Monitoring Drift

A deployed model meets a world that keeps changing: the inputs shift, the share of each class changes, and sometimes the relation between inputs and labels itself changes. Monitoring tries to notice before users do, but true labels often arrive weeks later, so most monitors watch something else: the input distributions, the model's scores, or the model's own confidence. The exercises build a classifier in a world with an interaction it cannot represent, then let five kinds of drift unfold (none, a harmless shift in an unused feature, a harmful shift into the interaction, concept drift, and label shift) and race five monitors against each: feature PSI, feature Kolmogorov-Smirnov tests, score PSI, confidence-based accuracy estimation, and late-labelled accuracy. Practice problems cover false alarms and persistence, importance-weighted drift, when confidence-based estimates work, correcting label shift without labels, and CUSUM.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Smoke detectors and thermometers

A smoke detector reacts quickly but also to burnt toast; a thermometer in the room tells you the house is cold only after it has cooled down. Model monitoring has the same choice. Watching the inputs is fast but raises alarms for changes that do not matter; watching accuracy is what matters but needs the true answers, which often arrive weeks later. And some changes are invisible in the inputs altogether: the same customers, the same images, but a different meaning.

🎮 MLOps lab

True accuracy: 0.7739 on day 0, 0.6815 on day 90 (harmful drift).

feature PSI above 0.1
alarm after 16 days
feature KS, p below 0.01/8
alarm after 9 days
score PSI above 0.1
alarm after 65 days
estimated accuracy down 2 points
no alarm
labelled accuracy down 2 points (14 days late)
alarm after 36 days

N4-1, seed 0. Drift starts on day 30 and reaches full strength on day 90; daily batches of 1,000; an alarm needs 3 days in a row. Longer bars mean earlier alarms.

Input monitors fire for harmless drift too; concept drift is visible only in labelled accuracy, which arrives weeks late; the model's confidence noticed nothing, because it is wrong exactly where the world changed.

Why engineers care

In Exercise 2, a change in what one feature meant cut accuracy from 0.77 to 0.60 while every input statistic stayed the same; only labelled accuracy noticed, 28 days after the drift began.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Labels for monitoring often arrive…
  2. 2. Input monitors can raise alarms for…
  3. 3. Concept drift means…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Covariate shift: P(x) changes, P(y | x) stays the same; harmful only where the model is wrong or extrapolates.
  • Label (prior) shift: P(y) changes, P(x | y) stays the same.
  • Concept drift: P(y | x) changes; inputs alone cannot reveal it.
  • Population stability index (PSI): Σ (c − a) ln(c/a) over bins of a feature; rules of thumb treat 0.1 as a shift and 0.25 as a large one.
  • Kolmogorov-Smirnov (KS) test: the largest gap between two empirical distribution functions, with a p-value.
  • Confidence-based performance estimation (CBPE): if scores are calibrated, expected accuracy is the mean of max(p, 1 − p); needs no labels.
  • Delayed labels: true outcomes arrive after days or weeks (loan defaults, churn, fraud chargebacks).
  • Alarm rules: thresholds, persistence (several periods in a row), and sequential tests such as CUSUM.
📝 Quick check (Level 1)
0/3 answered
  1. 1. PSI compares…
  2. 2. Confidence-based estimation assumes the model's scores are…
  3. 3. Label shift keeps unchanged…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

A model in a changing world

Exercise 1.

  • World: 8 standard normal features, a logistic label with weights (1.5, −1.2, 0.8, 0, 0.6, −0.5, 0, 0) plus an interaction 1.2·x2·x3 that a linear model cannot represent; logistic regression trained on 20,000 day-0 examples (accuracy about 0.77).
  • Drifts from day 30, full strength at day 90: feature 7 (unused) shifts 2 sd; features 2 and 3 move 1.25 sd in opposite directions; the weight of feature 1 reverses; positives rise from 42% to 67%.
  • Monitor statistics: PSI on reference deciles, the two-sample KS test, and the confidence-based accuracy estimate.

Practice.

  • Monitor several layers: inputs, scores, confidence, and labelled performance when it arrives.
  • Weight input alarms by importance, and use persistence or sequential tests to control false alarms.
  • Shorten label delay where possible (proxy labels, human review samples).
  • Expect concept drift to be invisible without labels; budget for labelled samples.
  • Know which drift you face: label shift can be corrected without retraining; concept drift cannot.
def psi(ref, cur, bins=10):
    e = np.quantile(ref, np.linspace(0, 1, bins + 1)[1:-1])
    a = np.bincount(np.searchsorted(e, ref), minlength=bins) / len(ref)
    c = np.bincount(np.searchsorted(e, cur), minlength=bins) / len(cur)
    a, c = np.clip(a, 1e-4, None), np.clip(c, 1e-4, None)
    return np.sum((c - a) * np.log(c / a))

def expected_accuracy(p):
    return np.mean(np.maximum(p, 1 - p))
🐍 Exercise 1: a world that drifts and three monitor statistics
Simulate five kinds of drift, train a model on day 0, and compute PSI, KS tests and the confidence-based accuracy estimate on day 90.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A harmless shift in an unused feature…
  2. 2. Requiring an alarm condition to hold several days in a row…
  3. 3. Under pure label shift, accuracy can often be restored by…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

What each monitor can see. A model’s score is a function of the inputs, so under concept drift, where P(x) is unchanged, every statistic of inputs and scores keeps its distribution: no input, score or confidence monitor can detect it. Only labels can. Conversely, input monitors detect covariate shift whether or not it matters.

Confidence-based estimation. If the model is calibrated, P(y = 1 | p) = p, then thresholding at 0.5 is correct with probability max(p, 1 − p) and the expected accuracy is its mean. Calibration on the reference data does not imply calibration after drift: when inputs move to where the model’s form is wrong (here, into the ignored interaction), the model stays confident and the estimate stays flat while accuracy falls.

Multiple tests and persistence. Testing 8 features daily at level 0.01/8 gives about a 1% chance of a false alarm per day, a few per year. Requiring 3 alarm days in a row multiplies the per-day probability by roughly itself twice for independent days, which removes them, while a real drift keeps the statistic high and costs only 2 extra days.

Label shift. If P(x | y) is fixed, the probability of predicting positive is a mixture of the class-conditional rates with the new prior as weights; inverting the confusion matrix from validation data estimates the prior (black-box shift estimation), and moving the threshold to the Bayes threshold for that prior restores accuracy.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Under concept drift with P(x) unchanged, input monitors…
  2. 2. The confidence-based estimate fails when…
  3. 3. Persistence rules work because…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which monitors notice which kinds of drift, how fast, and at what cost in false alarms?

History.

  • J. Schlimmer and R. Granger (1986) and G. Widmer and M. Kubat (1996) studied concept drift in incremental learning; J. Gama and colleagues’ survey (2014) organized drift detection.
  • E. S. Page (1954) introduced CUSUM; the Kolmogorov-Smirnov test dates from A. Kolmogorov (1933) and N. Smirnov (1948); PSI comes from credit scoring.
  • Z. Lipton, Y.-X. Wang and A. Smola (2018) introduced black-box shift estimation; S. Rabanser, S. Günnemann and Z. Lipton (2019) compared shift detectors (“Failing loudly”); tools such as Evidently, NannyML (confidence-based estimation) and cloud model monitors made these checks routine.

Exercise 2.

  • Daily batches of 1,000 predictions for 120 days (365 for the drift-free case); reference: 2,000 examples from day 0.
  • Monitors: any feature’s PSI above 0.1; any feature’s KS p-value below 0.01/8; score PSI above 0.1; estimated accuracy 2 points below the reference estimate; labelled accuracy over 7 days, 2 points below reference, with labels 14 days late. An alarm needs 3 days in a row.

Seed 0 (detection delay in days after day 30):

drift accuracy day 0 → 90 feature PSI feature KS score PSI estimated accuracy labelled accuracy
none (365 days) 0.7739 → 0.7743 no alarm no alarm no alarm no alarm no alarm
unused feature 0.7739 → 0.7755 12 6 never never never
into the interaction 0.7739 → 0.6815 16 9 65 never 36
concept 0.7739 → 0.6034 never never never never 28
label 0.7799 → 0.7460 never 43 65 never 46

Seeds 1 and 2: no false alarms in a year; the unused feature triggered PSI after 12 and 14 days and KS after 7; interaction drift (accuracy 0.665 and 0.668 at day 90) was flagged by KS after 7 and 8 days and by labels after 48 and 43; concept drift (0.608 and 0.608) only by labels, after 32 and 33 days; label shift by KS after 46 and 49 days and labels after 56 and 50; the confidence-based estimate never alarmed.

Findings.

  • With 3 days of persistence no monitor raised a false alarm in a year, in every seed.
  • Input monitors were fastest (6 to 18 days) but could not tell harmful from harmless drift: they fired as readily for the unused feature, which left accuracy unchanged.
  • Concept drift cut accuracy by 17 points and was invisible to every monitor except labelled accuracy (28 to 33 days, of which 14 were the label delay); the confidence-based estimate never alarmed, because the model stayed confident where it was wrong.
🐍 Exercise 2 (research): which monitors notice which kinds of drift, how fast, and at what cost in false alarms?
Race five drift monitors against five kinds of drift and measure detection delays and false alarms.

Drift monitoring in practice

  • Monitoring stacks (Evidently, NannyML, WhyLabs, Arize, SageMaker Model Monitor, Vertex AI Model Monitoring) compute per-feature drift, score distributions and, when labels arrive, performance by slice.
  • Alert design: importance weighting, persistence, sequential tests and per-slice baselines keep alerts actionable; dashboards show what changed, alerts fire on what matters.
  • Label delay is cut with proxy outcomes (early repayment behaviour, clicks), human review of sampled predictions, or active labelling of uncertain cases.
  • Satellite instruments drift as sensors age and orbits change; missions track calibration targets and cross-calibrate against other instruments, which plays the role of labelled accuracy.

References

  1. E. S. Page (1954). “Continuous inspection schemes.” Biometrika.
  2. G. Widmer and M. Kubat (1996). “Learning in the presence of concept drift and hidden contexts.” Machine Learning.
  3. J. Gama, I. Žliobaitė, A. Bifet, M. Pechenizkiy and A. Bouchachia (2014). “A survey on concept drift adaptation.” ACM Computing Surveys.
  4. Z. C. Lipton, Y.-X. Wang and A. Smola (2018). “Detecting and correcting for label shift with black box predictors.” ICML.
  5. S. Rabanser, S. Günnemann and Z. C. Lipton (2019). “Failing loudly: an empirical study of methods for detecting dataset shift.” NeurIPS.
  6. J. Quiñonero-Candela, M. Sugiyama, A. Schwaighofer and N. D. Lawrence, eds. (2009). “Dataset Shift in Machine Learning.” MIT Press.