Sub topic 10
Tracking Model Performance Once Labels Arrive
This chapter assumes you can train and evaluate a supervised model, and that you know the basics of Python, NumPy and pandas. Drift tests tell you the inputs changed. Performance monitoring tells you whether the model is still right. It is the only layer that measures the thing you care about, and it works only after ground truth (the true outcome for each prediction) is available.
What you need to log
To compute performance later, log at prediction time:
- A unique prediction ID.
- The timestamp and the model version.
- The input features, or a pointer to them.
- The prediction and, for classifiers, the score.
When the label arrives, store it with the same ID. Joining on the ID gives you a table of predictions with their true outcomes.
Choose metrics that match the task
Use the metrics you used in offline evaluation, so the numbers are comparable.
| Task | Common metrics |
|---|---|
| Classification | Precision, recall, F1, ROC AUC, log loss |
| Imbalanced classification | Precision, recall and PR AUC, not accuracy |
| Regression | MAE, RMSE, bias (mean error) |
Also compute metrics on slices, such as region, device type or customer segment. An overall metric can hold steady while one segment gets much worse.
Compute metrics per time window
Group the joined table by time window and compute the metric for each. Group by prediction time, not label arrival time. Otherwise a late batch of labels will distort the window it lands in.
import numpy as np
import pandas as pd
from sklearn.metrics import roc_auc_score
rng = np.random.default_rng(0)
n = 6000
df = pd.DataFrame({
"predicted_at": pd.date_range("2026-01-01", periods=n, freq="h"),
"score": rng.uniform(0, 1, n),
})
# The relationship between score and label weakens over time.
signal = np.linspace(0.9, 0.1, n)
noise = rng.uniform(0, 1, n)
df["label"] = (rng.uniform(0, 1, n) < signal * df["score"] + (1 - signal) * noise).astype(int)
df["week"] = df["predicted_at"].dt.to_period("W")
weekly = (
df.groupby("week")
.apply(lambda g: pd.Series({"n": len(g), "auc": roc_auc_score(g["label"], g["score"])}),
include_groups=False)
)
print(weekly.head(3))
print(weekly.tail(3))The AUC falls week by week because the score loses its link to the label.
Compare against a baseline
A number alone means little. Compare each window against:
- The offline test score, which is the expected level.
- A trailing average of recent healthy windows.
- A simple baseline, such as a majority-class predictor or last period's value.
Small windows give noisy metrics. With 50 labeled rows per window, a fluctuation in AUC may be chance. Report a confidence interval (for example, a bootstrap interval) or use larger windows, and require the drop to persist before you alert.
Common errors
- Selection bias in labels. If you only get labels for some predictions, for example loans you approved, the metric describes only that subset. It can look better than the model really is.
- Feedback loops. If the model's decisions change which outcomes you observe, the labels depend on the model.
- Mixing model versions. Compute metrics per model version, or a rollout hides the change.
- Label noise and definition changes. If the labeling process changes, the metric changes while the model does not.
Exercise
Your weekly accuracy stays flat at 95%, but the share of positive cases rose from 5% to 20% during the same period. Why is accuracy a poor signal here, and what would you track instead?
Show answer
Accuracy depends on class balance, so with rare positives a model can score high while missing many of them, and a change in the positive rate changes accuracy independently of model quality. Track precision, recall and PR AUC (or ROC AUC), and log the positive rate per window, ideally also per segment.