ML Systems Lab Open interactive version →
Advanced 55 min read distribution shiftcovariate shiftconcept driftlabel shiftmodel monitoring

Distribution Shift

The core assumption of supervised learning — train and deploy distributions match — is almost always violated in production.

You trained a recommendation model on January user data and shipped it in March. By May, engagement is down 30%. No error, the API responds, the model happily returns predictions. They are just *wrong*. Welcome to distribution shift — the quiet killer of production models, and the reason "it worked in testing" is never the end of the story.

Here is the trap that makes it so dangerous: the model never tells you it is lost. A confidence score measures how far an input sits from the model's decision boundary — *not* how far that input sits from anything the model was trained on. So a user unlike anyone in training can still get a *high-confidence* prediction that happens to be completely wrong. You do not find out from the model. You find out weeks later, when the real engagement numbers arrive.

The world can shift in three different ways, and telling them apart decides whether you need a five-minute fix or a two-week data effort.


Covariate shift — the inputs move

The *kinds of users* changed (a February product change brought new behaviour), but the underlying rule linking behaviour to engagement still holds. Your old labels are still correct; you just have fewer training examples that look like today's users. This one you can sometimes patch *without* retraining, by importance weighting — lean harder on the training examples that resemble current traffic and less on the ones that do not.


Concept drift — the rule itself moves (the bad one)

Now the *meaning* of the features changed. Fraudsters in 2024 have learned to make fraudulent transactions look legitimate, so a pattern that screamed "fraud" in your training data now looks perfectly innocent. Reweighting old data cannot save you — the old labels are simply *wrong* about today's world. There is no shortcut: you need fresh labelled data and a retrain.


Prior shift — just the mix changes (the easy one)

The fraud *rate* rose from 0.1% to 0.3%, but fraud itself still looks the same. Here you can adjust the model's outputs by re-estimating the new class balance — no retrain required.


You cannot fix what you cannot see

All of this is invisible without monitoring, so detection has to come *before* diagnosis. Watch each important feature's distribution against its training baseline — a common gauge is PSI (population stability index): under 0.1 is calm, 0.1–0.2 says "go investigate," and over 0.2 is a retraining trigger. Watch the *prediction* distribution too; if it drifts while the inputs look stable, that is a fingerprint of concept drift. And a neat trick to confirm covariate shift: train a quick classifier to tell "training row" from "production row" — if it succeeds easily, the two worlds really have diverged. Build this monitoring in from day one, or the business will discover the shift before you do.


The three shifts, in notation

The names map cleanly to which probability moved. Covariate shift: P(X) changes, P(Y|X) holds — the inputs move but the rule is intact. Label/prior shift: P(Y) changes, P(X|Y) holds — the class mix moves but each class still looks the same. Concept drift: P(Y|X) changes — the *rule itself* moves, which is the one no reweighting can fix. Being able to say "which distribution changed?" is exactly how you pick the response, so it's worth carrying the notation, not just the stories.


Detection has a metric menu, not just PSI

PSI is the industry default, but know the alternatives and when they're better. The KS test measures the largest gap between two CDFs (good for continuous features) — but its p-value is sample-size-sensitive: with enough production traffic, even a trivial, practically meaningless shift reads as statistically significant, so always check the *magnitude* (e.g. via PSI) before acting on a low p-value alone. Wasserstein (earth-mover) distance captures *how far* the mass moved, which PSI's binning can miss. KL / Jensen-Shannon divergence quantify distributional difference (JS is symmetric and bounded). MMD (maximum mean discrepancy) is a kernel-based two-sample test that works in high dimensions. For categorical features, compare frequencies (chi-squared) and watch for new categories. Use several — a shift that hides from one metric often shows in another.


Label shift can be estimated without new labels

Prior/label shift has a neat property: you can often correct it *without* fresh labels. Black Box Shift Estimation (BBSE) uses your existing model's confusion matrix plus the *distribution of its predictions* on the new data to estimate the new class priors, then reweights the outputs. So if only the class balance moved (fraud rate 0.1% → 0.3%, fraud still looks the same), you re-estimate the prior and adjust — no relabelling, no retrain. This is why diagnosing the shift *type* pays off: label shift is the cheapest to fix.


Adaptation strategies, cheapest to most involved

Match the response to the shift. Importance weighting for covariate shift (up-weight training rows resembling current traffic). Prior/output correction (BBSE) for label shift. Domain adaptation methods (align feature representations between source and target) when you have unlabelled target data. Online / continual learning to keep updating from a stream, and test-time adaptation (adjust batch-norm statistics or a few parameters to the incoming batch) for mild drift. And for concept drift, the honest answer remains fresh labels and a retrain — there is no free lunch when the underlying rule has genuinely changed.

Key points

Takeaway

A model outputs confident predictions on shifted data — no error fires, no uncertainty is signaled, and performance degrades silently until ground-truth labels arrive. Whether you can fix it without new labels depends on what type of shift occurred. Only monitoring catches it before the business does.

Recap

Check your understanding

Q1. Your fraud model was trained in 2022. In 2024, fraudsters adopt a new technique that makes fraudulent transactions look like legitimate ones. What type of shift is this and can it be fixed without new labels?

Q2. Describe what happens to a model's confidence scores under distribution shift, and why this makes shift especially dangerous. Which TWO of the following are true?

Q3. What is the difference between covariate shift and concept drift, and why does the distinction determine whether you can avoid retraining?

Q4. You run a KS test comparing training and production distributions of your top 5 features and find p < 0.01 for one feature. What does this mean and what should you do?

Q5. A model deployed in January shows 89% AUC. By June, AUC has drifted to 78%. Feature distribution monitoring shows stable PSI across all features. What type of shift does this suggest?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →