Sub topic 10
Tracking model performance once labels arrive
This chapter assumes you can train and evaluate a classifier with scikit-learn, use pandas groupby and merge, and read a confidence interval. Earlier chapters covered input drift and prediction drift. Those are indirect signals. Once ground-truth labels arrive, you can measure what you care about, which is whether the model is right.
Why this layer matters most
Drift tests tell you the inputs changed. They don't tell you whether the model got worse. Performance monitoring answers that directly. It is also the layer that decides whether a drift alert deserves action, which the later chapter on drift versus performance builds on.
The trade-off is time. Labels often arrive days or months after the prediction. This chapter covers the case where labels do arrive. The next chapter covers what to do while you wait.
What to log so labels can be joined later
Performance monitoring is a join between what the model said and what happened. Log these fields at prediction time:
- A unique
prediction_id. Without it you can't match a label to a prediction reliably. - The prediction timestamp.
- The model version.
- The raw score as well as the thresholded decision. You need the score to compute AUC and calibration, and to re-threshold later.
- The input features, or a pointer to them, so you can slice by segment.
Log these fields when the label arrives:
- The
prediction_id(or the entity key and a time rule that maps to one prediction). - The label value.
- The label timestamp.
Keep predictions and labels in separate tables and join them in the monitoring job. Labels arrive on their own schedule, so you will re-run the join as new ones come in.
Choosing metrics
Use the same metrics you used in offline evaluation, so the numbers are comparable. Add a few that only matter in production.
| Task | Core metrics | Notes |
|---|---|---|
| Binary classification | ROC AUC, precision, recall, F1 | AUC is threshold-free. Precision and recall depend on the threshold in use. |
| Probabilistic output | Log loss, Brier score, calibration error | Detects scores that stop meaning what they used to, even if ranking holds. |
| Regression | MAE, RMSE, bias (mean signed error) | Track bias separately. A model can have stable MAE and a growing bias. |
| Ranking and recommendation | NDCG, hit rate at k | Needs the same position and exposure logging as training. |
Two habits help. First, track a threshold-free metric and a threshold-based metric together. If AUC is flat but recall falls, the score distribution moved relative to your threshold. If AUC falls, the model's ranking got worse. Second, track label prevalence (the share of positives). Precision depends on prevalence, so a change in precision can come from the world changing even when the model's ranking is unchanged.
Windows: which date do you group by?
You must pick one date to assign each row to a window. There are two options.
- Prediction time. Each window answers "how good were the predictions made that week?" This is the usual choice because it lines up with drift windows and deployments.
- Label arrival time. Each window answers "what did we learn that week?" This mixes predictions from different periods and hides when the problem began.
With prediction time, recent windows are incomplete because many labels haven't arrived. A metric computed on the 10% of labels that came back first can be biased, since fast labels are often unrepresentative. For example, chargebacks that arrive within a day are not the same as those that arrive in 60 days. Report label coverage (labeled rows divided by predicted rows) next to every metric. Treat a window as mature only once coverage passes a threshold you choose, such as 90%, or once enough time has passed for most labels to arrive.
Sampling noise and confidence intervals
A weekly AUC of 0.81 after a week at 0.83 may mean nothing. Metrics computed on a few hundred labels are noisy, and plotting point estimates leads to false alarms. Attach an interval to each metric. A bootstrap works for any metric: resample the labeled rows with replacement many times, recompute the metric, and take the 2.5th and 97.5th percentiles.
Alert when the interval for the current window falls clearly below your baseline, not when the point estimate dips.
Worked example: weekly metrics with intervals and coverage
The script simulates a scored population. For the first 3,000 hours the label probability equals the score. After that the relationship weakens, which models concept drift. About 10% of labels are missing.
import numpy as np
import pandas as pd
from sklearn.metrics import roc_auc_score, precision_score, recall_score
rng = np.random.default_rng(0)
n = 6000
score = rng.uniform(0, 1, n)
p_true = np.where(np.arange(n) < 3000, score, 0.5 * score + 0.25)
truth = rng.binomial(1, p_true)
preds = pd.DataFrame({
"prediction_id": np.arange(n),
"predicted_at": pd.date_range("2026-01-01", periods=n, freq="h"),
"score": score,
})
labels = pd.DataFrame({"prediction_id": np.arange(n), "label": truth}).sample(
frac=0.9, random_state=0
)
joined = preds.merge(labels, on="prediction_id", how="left")
def bootstrap_auc_ci(y, s, n_boot=200, seed=0):
boot_rng = np.random.default_rng(seed)
aucs = []
for _ in range(n_boot):
idx = boot_rng.integers(0, len(y), len(y))
if y[idx].min() == y[idx].max():
continue
aucs.append(roc_auc_score(y[idx], s[idx]))
return np.percentile(aucs, [2.5, 97.5])
rows = []
for week, g in joined.groupby(pd.Grouper(key="predicted_at", freq="W")):
seen = g.dropna(subset=["label"])
if seen["label"].nunique() < 2:
continue
y = seen["label"].astype(int).to_numpy()
s = seen["score"].to_numpy()
decision = (s >= 0.5).astype(int)
lo, hi = bootstrap_auc_ci(y, s)
rows.append({
"week": week.date(),
"coverage": round(len(seen) / len(g), 2),
"prevalence": round(y.mean(), 2),
"auc": round(roc_auc_score(y, s), 3),
"auc_lo": round(lo, 3),
"auc_hi": round(hi, 3),
"precision": round(precision_score(y, decision, zero_division=0), 3),
"recall": round(recall_score(y, decision, zero_division=0), 3),
})
report = pd.DataFrame(rows)
print(report.to_string(index=False))Before the change, weekly AUC sits near 0.83. After about week 18 it falls toward 0.67, and the intervals separate from the baseline. The first full week after the break may look ambiguous, because it mixes both regimes. The weeks after it make the drop clear. Note that coverage stays near 0.9 throughout, so the drop is not an artifact of missing labels.
The monitoring flow
Slicing
An overall metric can stay flat while one segment collapses, because the healthy segments dominate the average. Compute the same metrics per slice for the segments that matter: region, device, customer tier, new versus returning users, and each model version if more than one is live. Small slices have wide intervals, so apply the same interval rule and set a minimum label count per slice.
Common errors
- Biased labels. If you only get labels for cases the model approved (a loan that was never granted has no repayment outcome), metrics describe only that subset. Consider logging a small random sample that bypasses the model decision to get unbiased labels.
- Feedback loops. If the model's decision influences the label, performance can look stable because the model shapes the outcome. Compare against a holdout or a randomized group where you can.
- Mixed model versions. After a deployment, an uncorrected window mixes two models. Group by version, not just by date.
- Late-arriving label corrections. Some systems revise labels. Recompute recent windows instead of freezing them.
- Prevalence shifts read as model decay. Report prevalence and use prevalence-robust metrics such as AUC alongside precision.
- Comparing to the wrong baseline. Offline test metrics are often optimistic. Use the first mature production windows as the baseline, and keep the offline number for context.
- Point-estimate alerts. Alerting on a single noisy value produces false alarms that teach people to ignore the alert.
Exercises
Exercise
A weekly report shows precision falling from 0.70 to 0.60 while AUC stays at 0.83 and the share of positive labels rose from 5% to 12%. Is this evidence the model's ranking got worse?
Show answer
No. AUC measures ranking and did not change. Precision depends on prevalence, and prevalence moved, so the change likely reflects the shift in the positive rate and the fixed threshold, not worse ranking. Check calibration and consider re-tuning the threshold before concluding the model degraded.
Exercise
Why should you attach label coverage to every windowed metric, and what goes wrong if you alert on the newest window using only the labels that have arrived so far?
Show answer
Coverage shows how much of the window's predictions the metric is based on. Early labels are often a biased subset (for example, the fastest-resolving cases), so the metric from an immature window can be off in either direction and cause false alarms or missed problems. Alert on mature windows, or report the immature window as provisional.