Sub topic 1
Why labels arrive late
A model's prediction is often made long before anyone learns whether it was right. A fraud model flags a card transaction today, but the chargeback may arrive 45 days later. This chapter covers why that delay distorts monitoring and how to evaluate on cohorts that have had enough time to mature.
Prerequisites
You should know binary classification metrics (accuracy, precision, recall, ROC AUC), basic pandas, and what a deployed model's prediction log contains. Each row in that log needs an id, a predicted_at timestamp, and a score.
Why labels arrive late
A label is the true outcome for a prediction. Labels often depend on events that happen after the prediction, such as a repayment, a churn decision, or a customer complaint. Some outcomes take weeks to appear, and some never appear for predictions that were never acted on.
The monitoring gap
On any given day, you can compute metrics only for predictions whose outcomes are known. Recent predictions have few or no labels. Metrics computed on everything, treating missing labels as negatives, quietly report a model that looks better or worse than it is.
Choosing a label maturity window
A maturity window is the time after prediction when you expect nearly all labels to have arrived. Set it from the observed lag distribution, not from a guess. Use the 95th or 99th percentile of past label delays, and report the coverage at that window.
import pandas as pd
def label_coverage(preds: pd.DataFrame, labels: pd.DataFrame,
now: pd.Timestamp, maturity: pd.Timedelta) -> pd.DataFrame:
"""Per-week count of predictions, mature predictions, and labeled predictions."""
cutoff = now - maturity
df = preds.merge(labels[["id", "label"]], on="id", how="left")
df["mature"] = df["predicted_at"] <= cutoff
df["week"] = df["predicted_at"].dt.to_period("W").dt.start_time
out = df.groupby("week").agg(
predictions=("id", "size"),
mature=("mature", "sum"),
labeled=("label", lambda s: s.notna().sum()),
)
out["coverage"] = out["labeled"] / out["predictions"]
return outEvaluating matured cohorts by prediction time
Group predictions by the week they were made, not the week their labels arrived. Score each cohort only after its maturity window has passed. This keeps older and newer predictions from mixing in one metric.
> Note
Exercise
A model's 99th-percentile label delay is 30 days. Today is June 30. Which predictions can you score, and why?
Show answer
Only predictions made on or before June 0 (30 days earlier, May 31 or earlier). Later predictions have not yet matured, so their labels may still be missing.