Sub topic 5
Covariate shift, label shift and concept drift
This chapter assumes you can train and evaluate a supervised model and that you know what a distribution and a hypothesis test are. Drift is a change between the data the model was trained on and the data it sees in production. Three kinds of change matter, and each one calls for a different check and a different fix.
The framing: what changed in the joint distribution
A supervised model learns from the joint distribution P(X, y), where X is the feature vector and y is the label. By the product rule, this equals P(X) · P(y | X). It also equals P(y) · P(X | y). Each kind of drift names the piece that moved while the others stayed fixed.
| Drift type | What changes | What stays the same | Example |
|---|---|---|---|
| Covariate shift | P(X) | P(y given X) | A lender starts receiving applications from younger customers |
| Label shift | P(y) | P(X given y) | A fraud model sees fraud rates double during a holiday sale |
| Concept drift | P(y given X) | Not assumed | The same transaction pattern stops being fraud after a policy change |
Covariate shift
Inputs look different, but the rule that maps inputs to labels is unchanged. The model can still be correct on the new inputs, as long as it has seen similar regions of feature space in training.
The danger is extrapolation. If the new inputs fall in regions the training data barely covered, the model's predictions there are unreliable. Covariate shift is also the easiest kind to detect, because it needs no labels. You compare feature distributions between a reference window and a current window, which the next chapters cover.
Label shift
The class mix changes, but each class still looks the same. A disease screening model may see more positive cases in winter. The features of a positive case are unchanged, but positives are more common.
Label shift breaks calibration and thresholds. A model's predicted probabilities encode the old class prior. If the true prior moves from 2% to 5%, scores are too low on average, and a threshold tuned for the old prior gives the wrong precision and recall. You often notice it first as prediction drift, a change in the distribution of scores, because labels arrive late.
Concept drift
The relationship between inputs and labels changes. The inputs may look identical, so feature tests can stay quiet while accuracy falls. Concept drift is the most damaging kind, and it is only fully visible with ground truth.
Concept drift comes in several temporal shapes:
- Sudden: a regulation, outage or product change flips the relationship overnight.
- Gradual: the old and new relationships coexist and the new one slowly dominates.
- Seasonal: the relationship cycles, so a model trained on summer data fails in winter.
Seeing the difference in code
This simulation builds one reference set and one current set per drift type. It then checks a fixed logistic model on each.
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
rng = np.random.default_rng(0)
def make(n, mean=0.0, boundary=0.0, pos_rate=None):
x = rng.normal(mean, 1.0, size=(n, 1))
y = (x[:, 0] > boundary).astype(int)
if pos_rate is not None:
keep = rng.random(n) < np.where(y == 1, pos_rate, 1 - pos_rate)
x, y = x[keep], y[keep]
return x, y
X_ref, y_ref = make(5000)
model = LogisticRegression().fit(X_ref, y_ref)
scenarios = {
"reference": make(5000),
"covariate shift": make(5000, mean=1.5),
"label shift": make(5000, pos_rate=0.9),
"concept drift": make(5000, boundary=0.8),
}
for name, (X, y) in scenarios.items():
print(f"{name:16s} accuracy={accuracy_score(y, model.predict(X)):.3f}")Covariate shift here barely hurts, because the model's rule is still right. Concept drift hurts the most, because the true boundary moved while the model's did not. Note that the label shift scenario only resamples rows by class and leaves the per-class feature distributions unchanged, which matches the definition.
Exercise
Your fraud model's input features pass every drift test, but precision has fallen steadily for three weeks after fraudsters changed tactics. Which drift type is this, and why did the feature tests miss it?
Show answer
Concept drift. P(y given X) changed, because the same kind of transaction is now more likely to be fraud, while P(X) stayed the same. Feature tests only compare P(X), so they cannot see a change in the input-to-label relationship. You need labels, or proxies for them, to detect it.