Sub topic 5
Covariate shift, label shift and concept drift
This chapter assumes you can train a supervised classifier, read a probability expression like P(y | x), and run a short Python script with NumPy and scikit-learn. It names the three ways production data can differ from training data. It also shows what each one looks like in monitoring and why they need different responses.
One joint distribution, two factorizations
A supervised model learns from pairs of features x and labels y drawn from a joint distribution P(x, y). That joint distribution can be split in two ways:
- P(x, y) = P(x) × P(y | x). Here P(x) is how often each input appears, and P(y | x) is the rule linking inputs to labels.
- P(x, y) = P(y) × P(x | y). Here P(y) is how common each class is, and P(x | y) is what inputs of each class look like.
Each of the three shifts holds one piece fixed and changes another.
The "stays the same" part of each definition is an assumption. You usually cannot verify it without labels, which is why the distinctions matter in practice.
Covariate shift
Covariate shift means the input distribution P(x) changes while the relationship P(y | x) stays the same. The word covariate is a statistics term for a feature.
Typical causes:
- A marketing campaign brings in younger customers.
- A new store region adds addresses the training data rarely contained.
- A sensor is replaced and its readings have a different range.
The model's rule is still correct. The problem is where it is asked to apply the rule. If production inputs land in regions where the training data was sparse, the model extrapolates, and error rises. If inputs move into regions the model already handles well, performance may not change, or may even improve. Covariate shift is therefore a risk signal, not proof of damage. A later chapter covers when it matters.
You can detect covariate shift without labels. Compare feature distributions between a reference window and the current window with the tests covered in later chapters.
Label shift
Label shift, also called prior shift, means the class frequencies P(y) change while P(x | y) stays the same. Fraudulent transactions look the same as before, but there are twice as many of them.
Label shift is a natural fit when the label causes the features. A disease causes symptoms, and fraud causes odd transaction patterns. During an outbreak, the share of sick patients rises, but each sick patient still shows the same symptom pattern.
Consequences:
- The model's predicted positive rate moves, because more inputs resemble the positive class.
- Calibrated probabilities become wrong. A model trained when 5% of cases were positive outputs scores that assume a 5% base rate. If the base rate becomes 15%, those scores are too low.
- Accuracy, precision and recall change, even though the model's understanding of each class is intact. Precision is especially sensitive to the base rate.
If labels are unavailable, label shift is hard to confirm directly. You see the effect as prediction drift. Methods such as black box shift estimation can estimate new class priors from predictions plus a confusion matrix from validation data. Both rely on the P(x | y) assumption.
Concept drift
Concept drift means the relationship P(y | x) itself changes. The same input now deserves a different label.
Typical causes:
- Fraudsters adapt to the detector, so transactions that were safe become fraudulent.
- Customer behavior changes after a price increase, so the same user profile now churns at a different rate.
- A regulation changes what counts as a default or an eligible claim.
- The definition of the label changes upstream, for example a "conversion" now includes trial signups.
Concept drift is the dangerous one. The model's learned rule is now wrong, and nothing in the inputs has to look different. Feature distributions can be perfectly stable while accuracy collapses. Only labels, or reliable proxies for them, reveal it.
Concept drift also has different shapes over time:
- Sudden: the relationship flips at a known moment, such as a policy change.
- Gradual: the old and new relationships coexist and the mix slowly changes.
- Incremental: the relationship moves a little each week.
- Recurring: the relationship cycles, for example by season.
The shape affects how you pick comparison windows and how quickly retraining helps.
Simulating the three shifts
The script below builds one setup where all three shifts can be created cleanly. In the base data, y is 0 or 1 with equal probability, and x is drawn from a normal distribution with mean +1 for class 1 and mean -1 for class 0. With these settings, P(y = 1 | x) is exactly the sigmoid of 2x, so a logistic regression is the correct model for the base data. It then trains on the base window and evaluates on four windows.
import numpy as np
from sklearn.linear_model import LogisticRegression
rng = np.random.default_rng(0)
def sigmoid(z):
return 1.0 / (1.0 + np.exp(-z))
def base_window(n):
y = rng.binomial(1, 0.5, n)
x = rng.normal(np.where(y == 1, 1.0, -1.0), 1.0)
return x.reshape(-1, 1), y
def covariate_shift(n):
# P(x) moves right; P(y | x) is unchanged.
x = rng.normal(1.5, 1.0, n)
y = rng.binomial(1, sigmoid(2 * x))
return x.reshape(-1, 1), y
def label_shift(n):
# P(y) falls to 10%; P(x | y) is unchanged.
y = rng.binomial(1, 0.1, n)
x = rng.normal(np.where(y == 1, 1.0, -1.0), 1.0)
return x.reshape(-1, 1), y
def concept_drift(n):
# Same P(x) as the base window; the label rule is reversed.
x, _ = base_window(n)
y = rng.binomial(1, sigmoid(-2 * x[:, 0]))
return x, y
X_train, y_train = base_window(5000)
model = LogisticRegression().fit(X_train, y_train)
windows = {
"base": base_window,
"covariate shift": covariate_shift,
"label shift": label_shift,
"concept drift": concept_drift,
}
print(f"{'window':<16}{'mean x':>8}{'label rate':>12}{'pred rate':>11}{'accuracy':>10}")
for name, make in windows.items():
X, y = make(5000)
pred = model.predict(X)
print(
f"{name:<16}{X.mean():>8.2f}{y.mean():>12.2f}"
f"{pred.mean():>11.2f}{(pred == y).mean():>10.2f}"
)Exact numbers depend on the random seed and library version, but the pattern should hold:
- Covariate shift: the mean of x moves from about 0 to about 1.5. The model's rule is still right, so accuracy stays at or above the base level. The label rate also rises, because inputs with larger x are more likely positive under the unchanged rule.
- Label shift: the mean of x moves down and the predicted positive rate falls to near the new 10% label rate. The model still separates the classes as before, but the base rate it implicitly assumed (50%) is wrong.
- Concept drift: the mean of x and the label rate stay near the base values, because only the pairing between inputs and labels changed. Accuracy falls well below the base window, to below 50%, since the model now predicts the opposite of the truth for most inputs.
The last case is the practical lesson. Feature statistics and the label rate looked healthy, and the model was badly wrong.
What each shift looks like in monitoring
| Shift | What changes | Visible in feature drift tests | Visible in prediction drift | Needs labels to confirm | Usual first response |
|---|---|---|---|---|---|
| Covariate shift | P(x) | Yes | Often | No, but labels show whether it hurts | Check performance, retrain on recent data if it hurts |
| Label shift | P(y) | Sometimes, in features linked to the class | Yes | Yes | Re-estimate priors, recalibrate or adjust thresholds |
| Concept drift | P(y given x) | Not necessarily | Not necessarily | Yes | Retrain with new labels, revisit features |
Gotchas
- Real data mixes the shifts. A pandemic can change who shops (covariate), how many orders are returned (label) and what shoppers do with the same cart (concept) at once. The categories help you form hypotheses and are not clean diagnoses.
- The "unchanged" assumption can fail silently. Label shift methods assume P(x | y) is stable. If positives themselves change appearance, you have concept drift disguised as label shift.
- Training set sampling creates fake label shift. If you downsampled negatives to balance training data, production will always show a different P(y). Correct for this when interpreting prediction rates.
- Broken pipelines mimic drift. A feature that suddenly becomes all zeros looks like covariate shift. Check data quality before concluding the world changed.
- Not every shift needs action. Drift in a feature the model barely uses may be harmless. Drift in a decisive feature may matter a lot even when it is small.
Exercise
A credit model was trained on loan applicants. After a recession begins, the applicant mix and their income distributions look the same as before, but people with the same income and credit history now default more often. Which shift is this, and can feature drift tests on the inputs alone detect it?
Show answer
This is concept drift, because P(y | x) changed while P(x) did not. Feature drift tests on the inputs compare P(x), which is unchanged, so they will not detect it. You need default outcomes (labels) or a proxy such as early delinquency to see the problem.
Exercise
In the simulation, a fraud model sees the fraud rate rise from 1% to 3% while fraudulent transactions look the same as before. Name the shift and say which monitored signal would change first without labels.
Show answer
This is label shift, since P(y) changed and P(x | y) did not. The first signal without labels is the prediction distribution: the share of transactions flagged as fraud, or the average predicted fraud score, should rise.