Sub topic 4
Evaluating Matured Cohorts by Prediction Time
Assume you know binary classification metrics, pandas, scikit-learn, and how a deployed model logs predictions. The key idea in this chapter is to evaluate predictions only after enough time has passed for their outcomes to become observable.
Why prediction time matters
Suppose a fraud model predicts whether a card transaction is fraudulent. A chargeback may arrive several weeks later. If you calculate accuracy today using only outcomes already reported, recent predictions are treated differently from older predictions.
This creates a misleading comparison. Older predictions have had more time to receive labels. Recent predictions may appear unusually good simply because their difficult cases have not been reported yet.
A maturity window is the amount of time you wait before including a prediction in an evaluation cohort. If the current time is June 30 and the maturity window is 30 days, evaluate predictions made on or before May 31.
A cohort is a group of predictions selected by a shared property. Here, cohorts are usually grouped by the time the predictions were made:
- Daily or weekly prediction cohorts show how performance changes over time.
- Each cohort is scored only after it reaches the maturity window.
- The evaluation should report how many predictions have usable labels.
Selecting a matured cohort
Let t_prediction be the time when the model produced a prediction. For evaluation time t_now and maturity duration M, a prediction is mature when:
t_prediction <= t_now - M
The maturity rule must reflect the label process. For churn, you might wait 90 days after prediction. For payment default, you might wait until the contractual delinquency period has passed. A single fixed window is unsafe if some outcomes arrive much later than others.
The following function filters mature predictions, joins known labels, and returns both AUC and coverage. Coverage is the fraction of all predictions old enough to be evaluated. It does not mean that every mature prediction has a confirmed label.
import pandas as pd
from sklearn.metrics import roc_auc_score
def matured_auc(preds, labels, now, maturity):
"""Calculate AUC for predictions old enough to evaluate."""
cutoff = now - maturity
mature = preds[preds["predicted_at"] <= cutoff].copy()
joined = mature.merge(
labels[["id", "label"]],
on="id",
how="left",
)
# This assumption is valid only when missing outcomes mean negative.
joined["label"] = joined["label"].fillna(0).astype(int)
if joined["label"].nunique() < 2:
raise ValueError("AUC requires both positive and negative labels")
auc = roc_auc_score(joined["label"], joined["score"])
coverage = len(mature) / len(preds) if len(preds) else 0.0
return {"auc": auc, "coverage": coverage}Comparing cohorts safely
For trend monitoring, assign each mature prediction to a bucket based on its prediction timestamp. Then calculate metrics separately for each bucket. Do not group by label-arrival date when the question is whether model behavior changed over time. Arrival date measures the reporting process as well as model performance.
| Cohort | Mature predictions | Labeled outcomes | AUC | Label coverage |
|---|---|---|---|---|
| May 1–7 | 12,400 | 11,980 | 0.84 | 96.6% |
A cohort with low label coverage should be marked provisional. Compare cohorts only when their label definitions, maturity rules, and inclusion filters are the same.
Practical checks
Before publishing a cohort metric, verify:
- The prediction timestamp uses the model's event time, not ingestion time.
- The maturity window covers the normal outcome delay.
- Duplicate prediction IDs are handled consistently.
- Label joins cannot use information unavailable at prediction time.
- The dashboard shows mature count, labeled count, and missing-label count.
- Metrics with only one observed class are reported as unavailable, not zero.
Exercise
A model predicts customer churn on January 1, and churn labels require 60 days to observe. On February 15, which prediction dates may be included in a matured cohort?
Show answer
Predictions made on or before December 17, assuming the 60-day window is measured from prediction time and the dates are handled consistently.