Lecture 5 of 1418 minInteractiveFree lecture

Monitoring and drift

Models decay quietly as the world changes. Learn what to monitor — from latency to input drift to delayed quality metrics — measure drift with PSI and statistical tests, tell data drift from concept drift, and tune alerts that catch real incidents without drowning the team.

In this lecture you will

  • Build a layered monitoring plan for a model in production
  • Measure input drift with the population stability index and the Kolmogorov–Smirnov test
  • Distinguish data drift from concept drift, and know which signals reveal each
  • Tune alert thresholds and plan the response — rollback, retraining or fixing the data

On launch day a model is as good as it will ever be. After that, customers change, products change, fraudsters adapt and upstream systems get “improved”. None of this raises an error: the model keeps returning confident predictions that are slowly getting worse. Monitoring is how you notice — ideally before your customers do.

What to monitor

Good monitoring is layered, from the cheapest and fastest signals to the slowest and most meaningful:

  1. Service health — traffic, error rate, latency. The same as for any API.
  2. Data quality — schema, missing values, ranges: the expectations from lecture 2, now run on live requests.
  3. Drift — how today’s inputs and predictions compare with the training data.
  4. Model quality — accuracy, AUC or error against real outcomes, once the labels arrive.
  5. Business outcome — the metric the model was built to move, such as churn, fraud losses or conversion.

The first three are available immediately; the last two arrive late but tell you what actually matters.

Measuring drift

The most common drift measure in industry is the population stability index (PSI). Split the training distribution of a feature into ten equal-sized bins, see what share of today’s values falls into each, and add up how far each share moved:

PSI=∑i=110(ai−ei) ln⁡aiei\text{PSI} = \sum_{i=1}^{10} (a_i - e_i)\,\ln\frac{a_i}{e_i}

where e is the expected share (10% per bin) and a the actual share in production. A common rule of thumb: below 0.1 stable, 0.1–0.25 moderate, above 0.25 significant. Statistical tests such as Kolmogorov–Smirnov answer a different question — is there any difference at all? — and with enough data the answer is almost always yes.

InteractiveMeasuring drift in one featureShift the distribution and change the sample size
Loading visual…

Keep a small shift and raise the number of samples: the KS test becomes ‘significant’ while PSI stays low. Change the spread without moving the mean: the outer deciles light up.

import numpy as np

def psi(train, live, bins=10):
    edges = np.quantile(train, np.linspace(0, 1, bins + 1)[1:-1])      # deciles of the training data
    expected = np.bincount(np.searchsorted(edges, train), minlength=bins) / len(train)
    actual = np.bincount(np.searchsorted(edges, live), minlength=bins) / len(live)
    actual = np.clip(actual, 1e-4, None)
    return float(np.sum((actual - expected) * np.log(actual / expected)))
Data drift
A change in the distribution of the model’s inputs, also called covariate shift.
Prediction drift
A change in the distribution of the model’s outputs — for example, far more customers flagged than usual.
Concept drift
A change in the relationship between inputs and the outcome, so the same inputs now mean something different.
PSI
Population stability index: a measure of how much a distribution has shifted, compared bin by bin with a reference.
Label delay
The time between a prediction and the moment its true outcome becomes known.

Data drift versus concept drift

Not every drift hurts, and not every harmful change shows up as drift. The difference matters for what you monitor and how you respond.

AnimationData drift, concept drift and retraining
Loading animation…
  1. At training timeA fraud model uses two inputs: payment amount and distance from the customer’s usual location. Its boundary separates fraud from normal payments well.
  2. Data driftOver the following months payments get larger and closer to home. The inputs have clearly shifted — a drift monitor would notice — but the boundary still classifies them correctly.
  3. Concept driftFraudsters change tactics: small payments, far from home. These fall on the “approve” side of the old boundary. The model misses them, and the input distribution barely changes.
  4. Labels reveal itOnly when chargebacks confirm the fraud a week or more later does measured accuracy fall below the alert threshold.
  5. RetrainTraining on recent labeled data moves the boundary to match the new pattern, and accuracy recovers.

Alerts that people trust

Every alert is a trade-off. Thresholds that are too sensitive fire on normal noise, and a team that is paged for nothing soon ignores the pager. Thresholds that are too loose let real incidents run for weeks. Use the dashboard below to find the balance.

InteractiveSixty days of a model in productionPick an incident, then tune the thresholds
Loading visual…

Each scenario is caught by a different panel. The schema change shows up at once as input drift; the slow release as latency; concept drift only through quality — a week late, because labels take seven days. Push the thresholds too far and false alarms appear.

When an alert fires, respond in order of likelihood and cost:

  • Check the data first. Most “drift” is a broken pipeline: a renamed column, a new code, a unit change. Fix it at the source.
  • Roll back if a recent model or code release caused the problem.
  • Retrain on recent data when the world has genuinely changed — on a schedule, or triggered by monitoring. Compare the new model with the current one (a champion–challenger evaluation) before promoting it.
  • Rethink the features or the model when retraining keeps losing ground.

This completes the first module. You can now take a model from a notebook to a monitored production system: reliable data pipelines, tracked and reproducible training, safe serving and rollouts, and monitoring that closes the loop. The next module builds the platform that makes this repeatable across many models — CI/CD for machine learning, feature stores, model registries and training orchestration.

Key takeaways

  • Monitor in layers — service health, data quality and drift, prediction distributions, model quality with delayed labels, and the business outcome.
  • PSI measures how much a distribution has shifted; statistical tests only say whether a shift is detectable, which with large samples is almost always.
  • Data drift changes the inputs; concept drift changes what the inputs mean. Concept drift is only visible through labeled outcomes or business metrics.
  • Every alert needs an owner and a runbook, and thresholds should be tuned on history to balance fast detection against false alarms.

Check your understanding

4 questions · answers explained

Q1The population stability index of a key feature rises to 0.35 this week. What does that indicate?

A common rule of thumb reads PSI below 0.1 as stable, 0.1–0.25 as a moderate shift and above 0.25 as significant. PSI describes the inputs; whether accuracy suffers must be checked separately.

Q2Why does quality monitoring (for example AUC) often detect problems later than drift monitoring?

Whether a customer churned or a payment was fraud is only known later. Input and prediction drift can be measured immediately, so they serve as early warnings while quality metrics confirm the impact.

Q3Fraudsters switch to small payments that look like normal customers. The input distribution barely changes, but fraud losses rise. What is this?

The inputs look much the same, but what they mean has changed. Drift monitors on the inputs may stay quiet; labeled outcomes and business metrics reveal the problem, and retraining on recent labels fixes it.

Q4With a million production samples, a Kolmogorov–Smirnov test reports p < 0.001 for a feature whose mean moved by 0.5%. What is the best response?

With enough data, statistical tests detect differences too small to matter. Alert on effect sizes and thresholds tuned to business impact, not on p-values alone.

You’ve finished the free lectures.

Continue with the remaining 9 lectures of MLOps: Machine Learning in Production — one-time purchase of $69₹4,499.