Sub topic 13
Backtesting estimates once labels arrive
An estimate of model performance is a prediction, so it needs scoring like any other prediction. This chapter shows how to score estimates from calibrated probabilities, importance weighting, or an error model against the labels that arrive later. It also covers how to turn the results into a decision about when to trust each estimator.
This chapter assumes you can compute accuracy and ROC AUC, and that you have read the earlier chapters on matured cohorts and on estimating performance without labels. You should be comfortable with pandas.
What a backtest compares
A backtest pairs two numbers for the same cohort of predictions:
- The estimate: the performance you computed when the cohort was fresh, before its labels existed.
- The actual: the performance computed on that cohort once its labels matured.
The gap between them is the estimator's error. Collect many cohorts and you can measure how large that error is, whether it leans in one direction, and whether it grows when the model really degrades.
The comparison is only meaningful if you saved the estimate at the time. Re-running an estimator today on an old cohort uses information you did not have then. It can also use a newer model version or a recalibrated calibrator. So log every estimate when you make it.
What to record
| Field | Why it matters |
|---|---|
| cohort | The prediction-time window the estimate covers, such as the week starting 2026-03-02. |
| estimated_at | The timestamp when the estimate was produced. |
| method | Which estimator ran: calibrated-probability, importance-weighted, or error model. |
| model_version | A new model version starts a new backtest history. |
| estimated | The point estimate of the metric. |
| interval | The lower and upper bounds, if the method gives them. |
| n | The number of predictions in the cohort. |
When labels mature, you add actual and the matured label coverage to the same row.
Comparing like with like
Most backtesting errors come from comparing two numbers that do not measure the same thing. Check these four points before you trust any error figure.
- Same cohort. Group both numbers by prediction time, not by the date the label arrived.
- Same metric and threshold. If the estimate is accuracy at threshold 0.5, the actual must be accuracy at 0.5.
- Same label handling. If the matured actual treats a missing label as negative, say so. The estimate should target that same quantity, because the estimator cannot see any other.
- Mature enough. Score only cohorts past the maturity window, and report their label coverage. An "actual" computed on 60% of labels is itself an estimate.
Measuring estimator quality
One summary number is not enough. Use several, because each answers a different question.
- Bias: the mean of estimate minus actual. A negative bias means the estimator is pessimistic. A positive bias means it hides problems, which is the dangerous direction.
- Mean absolute error (MAE): the typical size of the miss, ignoring direction.
- Within-tolerance rate: the share of cohorts where the miss is smaller than the error you can accept, for example 0.02 accuracy.
- Detection precision and recall: treat "performance dropped by more than X" as a binary event. Recall is the share of real drops the estimate flagged. Precision is the share of flags that were real drops. This is the measure that matters most for alerting.
- Interval coverage: if the estimator reports 95% intervals, about 95% of actuals should fall inside them.
The actual metric also has sampling noise. With 1,000 predictions at 0.90 accuracy, the standard error is about sqrt(0.9 × 0.1 / 1000) ≈ 0.0095. An estimator that misses by 0.01 on such a cohort may be as good as it can be, so compare the error to that standard error before you call it a failure.
A runnable backtest
The code below builds a synthetic estimate log in which the estimator under-reacts to a real drop. It then computes the measures above, separately for stable and degraded cohorts.
import numpy as np
import pandas as pd
def backtest(df: pd.DataFrame, baseline: float,
drop: float = 0.03, tolerance: float = 0.02) -> dict:
"""Score logged estimates against matured actuals.
df columns: cohort, estimated, actual, n
A cohort counts as degraded if actual < baseline - drop.
The estimator flags a cohort if estimated < baseline - drop.
"""
d = df.copy()
d["error"] = d["estimated"] - d["actual"]
d["se_actual"] = np.sqrt(d["actual"] * (1 - d["actual"]) / d["n"])
d["degraded"] = d["actual"] < baseline - drop
d["flagged"] = d["estimated"] < baseline - drop
tp = int((d["degraded"] & d["flagged"]).sum())
fn = int((d["degraded"] & ~d["flagged"]).sum())
fp = int((~d["degraded"] & d["flagged"]).sum())
def safe_ratio(a, b):
return a / b if b else float("nan")
stable = d[~d["degraded"]]
bad = d[d["degraded"]]
return {
"bias_all": float(d["error"].mean()),
"bias_stable": float(stable["error"].mean()) if len(stable) else float("nan"),
"bias_degraded": float(bad["error"].mean()) if len(bad) else float("nan"),
"mae": float(d["error"].abs().mean()),
"within_tolerance": float((d["error"].abs() <= tolerance).mean()),
"mean_se_actual": float(d["se_actual"].mean()),
"detection_recall": safe_ratio(tp, tp + fn),
"detection_precision": safe_ratio(tp, tp + fp),
}
rng = np.random.default_rng(0)
cohorts = pd.date_range("2026-01-05", periods=20, freq="W-MON")
baseline = 0.92
true_drop = np.where(np.arange(20) >= 12, 0.06, 0.0) # real degradation
actual = baseline - true_drop + rng.normal(0, 0.005, 20)
# The estimator only sees part of the drop and carries a small noise term.
estimated = baseline + 0.6 * (actual - baseline) + rng.normal(0, 0.008, 20)
log = pd.DataFrame({"cohort": cohorts, "estimated": estimated,
"actual": actual, "n": 2000})
for name, value in backtest(log, baseline).items():
print(f"{name:>20}: {value:.4f}")In a run like this, bias_stable is near zero while bias_degraded is clearly positive. The estimator looks fine on average but is optimistic exactly when it matters. An overall bias or MAE would have hidden that, which is why the code splits the error by regime.
Reading the results
Look at error as a function of conditions, not only as one average. The useful splits are:
- Stable versus degraded cohorts, as in the code above.
- Before versus after a shift in the inputs, since importance weighting and calibration can behave differently once the input distribution moves.
- By segment, such as region or product, if the metric will be used per segment.
- By cohort size, because small cohorts have noisy actuals.
Estimator-specific checks
- Calibrated-probability estimates fail when calibration breaks. Backtest the calibration itself on matured cohorts, for example with a reliability table. A rising error in the estimate usually follows a rising calibration error.
- Importance-weighted estimates fail when the labeled reference set does not cover the new inputs, or when the relationship between inputs and outcome has changed. Watch the effective sample size of the weights. A few huge weights mean the estimate rests on a handful of rows.
- Error-model estimates fail when the model that predicts errors was trained on a different regime from the one now in production. Retrain it and backtest again after each model change.
Common errors
- Backtesting on immature cohorts. Early actuals are biased by the missing labels, so the estimator appears wrong when the actual is wrong.
- Tuning on the backtest. If you choose thresholds or the estimator's settings by looking at the same cohorts you then report, the reported error is too small. Hold back the most recent cohorts for the final check.
- Judging with too few cohorts. Ten stable cohorts say nothing about behavior during a drop. A backtest with no degraded cohorts cannot say whether the estimator detects degradation.
- Mixing model versions. Errors from before and after a retrain belong to different estimators in practice.
- Reporting only the mean. Bias that cancels across regimes looks like accuracy.
Deciding when to trust an estimator
Turn the backtest into an explicit policy instead of a feeling. A simple scheme sets a tolerance and a minimum history, then assigns a status.
| Status | Condition | How the estimate is used |
|---|---|---|
| Trusted | At least 12 mature cohorts, MAE within tolerance, detection recall above your target | Can trigger alerts on its own |
| Advisory | Within tolerance on stable cohorts but weak detection recall, or too little history | Shown on dashboards, alerts need a second signal such as drift |
| Suspended | Recent bias or coverage outside limits | Hidden or flagged until the estimator is fixed and re-backtested |
Re-evaluate the status every time a new cohort matures. The same job that scores the cohort can update the status, which keeps the policy current without manual review.
Exercise
Your estimator reports a mean absolute error of 0.008 over 30 matured weekly cohorts, and each cohort has 2,000 predictions at about 0.92 accuracy. Only 2 of the 30 cohorts were degraded, and the estimator flagged neither. Should you trust it for alerting? Give two reasons and name one measurement that would settle it.
Show answer
No. First, the standard error of each actual is about sqrt(0.92 × 0.08 / 2000) ≈ 0.006, so a MAE of 0.008 mostly reflects noise on stable cohorts, which says nothing about drops. Second, detection recall is 0 out of 2 on the degraded cohorts, so the estimator has so far missed every real drop. Compute the bias and detection recall on degraded cohorts only, and add more degraded cohorts from past incidents or simulated degradation before giving it alerting duty. Until then, use it as advisory only.