Sub topic 2
What offline evaluation tells you and what it cannot
This chapter assumes you can read short Python snippets and know the common model metrics (accuracy, precision, recall, AUC, latency). It also assumes you know what a held-out test set is. The previous chapter explained why a model release carries risk that a code release does not. This chapter covers the first line of defense against that risk, offline evaluation, and shows where it stops being reliable.
What offline evaluation is
Offline evaluation scores a candidate model on data that has already been collected. Nobody is waiting for the answer, and no user sees the output. A typical setup has three parts:
- A frozen dataset, usually a held-out slice of historical data that the model never trained on.
- One or more metrics, such as AUC, precision at a fixed recall, or RMSE.
- A baseline, normally the model that is currently in production, scored on exactly the same data.
Offline evaluation is cheap, fast, repeatable, and safe. You can run it a hundred times a day, in CI, with no risk to users. That is why every serious release process starts with it.
What it does tell you
A well-built offline evaluation answers a narrow set of questions reliably.
- Is the model broken? A candidate that scores far below the baseline, or below a trivial predictor, should never reach production.
- Did a change help on the data we have? Comparing candidate and baseline on the same frozen set isolates the effect of the change from the noise of different data.
- Where does it fail? Slicing metrics by segment (country, device, new versus returning user, label class) reveals weak spots that a single global number hides.
- Does the pipeline work? Running the full feature and inference code on historical data catches schema bugs, null handling errors, and serialization problems.
Treat offline evaluation as a filter. It removes candidates that are clearly bad. It does not certify that the survivors are good.
What it cannot tell you
Each limit below corresponds to a specific mechanism. Knowing the mechanism tells you which later rollout strategy addresses it.
The data is from the past
The test set was generated by the old system, in the old world. If user behavior, input distributions, or upstream data change after the snapshot, the offline score no longer describes production. This is distribution shift. A model can look excellent on last quarter's data and degrade on this week's traffic.
The data was shaped by the old model
In many systems the logged data only exists because the current model made certain decisions. A loan model only sees repayment outcomes for applicants it approved. A recommender only sees clicks on items it showed. This is selection bias, also called the feedback loop problem. A candidate that makes different decisions is being scored on outcomes it never had a chance to cause, so its offline score can be too optimistic or too pessimistic, and you cannot tell which.
The metric is a proxy
Offline metrics measure prediction quality. The business cares about outcomes such as revenue, retention, or fraud losses. A higher AUC does not guarantee higher revenue, because the relationship depends on thresholds, costs, and how downstream systems use the score. A/B testing exists to measure the business outcome directly.
Training-serving skew and leakage
Offline, features come from a batch pipeline over historical tables. Online, they come from a different code path with different freshness and different null behavior. If the two disagree, the production model sees inputs it was not evaluated on. Leakage is the opposite problem: a feature that is available offline, such as a field filled in after the event, but not at prediction time. Leakage inflates offline scores and then collapses in production.
System behavior is not measured
Offline evaluation does not tell you the p95 latency under load, memory use, timeout rates, cold-start behavior, or what happens when a feature store is slow. A more accurate model that is twice as slow can still make the product worse.
Multiple comparisons inflate the winner
If you try 50 candidates against the same test set and ship the best, the best score is partly luck and partly overfitting to that set. The more you reuse a test set, the less it behaves like unseen data.
The table summarizes each limit and the technique later in this tutorial that addresses it.
| Limit of offline evaluation | Why it happens | What addresses it |
|---|---|---|
| Distribution shift | Test data is older than live traffic | Shadow deployment on live inputs |
| Selection bias | Logged outcomes depend on the old model | A/B testing with randomization |
| Proxy metric | Prediction quality is not business value | A/B testing on a business outcome |
| Training-serving skew, leakage | Offline and online feature paths differ | Shadow deployment, prediction logging |
| No system measurements | No real load or real dependencies | Canary release with guardrail metrics |
| Reused test set | Repeated selection on the same data | Fresh data from live experiments |
Measuring offline results with uncertainty
A single number such as "AUC 0.912 versus 0.908" is not enough. The test set is a sample, so the difference has sampling error. A bootstrap gives a quick estimate of how large that error is by resampling the test set with replacement and recomputing the difference many times.
The code below compares a candidate and a baseline on the same test examples. It uses a paired bootstrap, so both models are scored on the same resampled rows each time. It needs numpy and scikit-learn.
import numpy as np
from sklearn.metrics import roc_auc_score
def paired_bootstrap_auc_diff(y_true, p_base, p_cand, n_boot=1000, seed=0):
rng = np.random.default_rng(seed)
y_true = np.asarray(y_true)
p_base = np.asarray(p_base)
p_cand = np.asarray(p_cand)
n = len(y_true)
diffs = []
while len(diffs) < n_boot:
idx = rng.integers(0, n, size=n)
if len(np.unique(y_true[idx])) < 2:
continue # AUC is undefined with a single class
diffs.append(
roc_auc_score(y_true[idx], p_cand[idx])
- roc_auc_score(y_true[idx], p_base[idx])
)
diffs = np.array(diffs)
return diffs.mean(), np.percentile(diffs, [2.5, 97.5])
rng = np.random.default_rng(42)
y = rng.integers(0, 2, size=2000)
base = np.clip(y * 0.30 + rng.normal(0.35, 0.25, size=2000), 0, 1)
cand = np.clip(y * 0.32 + rng.normal(0.35, 0.25, size=2000), 0, 1)
mean_diff, (low, high) = paired_bootstrap_auc_diff(y, base, cand)
print(f"mean diff {mean_diff:.4f}, 95% interval [{low:.4f}, {high:.4f}]")If the interval contains zero, the offline data does not show that the candidate is better. That is a normal result for a small improvement. It does not mean the candidate is worse, and it does not mean it is the same.
Slicing
Compute the same comparison per segment. A candidate with a better global score can be worse on a segment that matters, for example a small country or a rare class. Check slices that are large enough to be meaningful, and remember that many slices means many chances for a false alarm.
Where offline evaluation sits in the release flow
Offline evaluation is the first gate. Each later stage removes a risk the earlier stage could not see.
Not every release uses every stage. The last chapter of this tutorial covers choosing and combining them.
Common errors
- Evaluating on training data or near-duplicates. If the test set overlaps the training set, for example the same user appears in both, scores are inflated. Split by the unit that matters (user, session, time), not by row.
- Random splits for time-dependent data. A random split lets the model see the future. Use a time-based split so the test set is later than the training set.
- Comparing against a stale baseline. Score the baseline on the same test set with the same code. Reusing a number from last month's report compares different data.
- Tuning the threshold on the test set. Choose thresholds on a validation set, then report on the test set once.
- Treating a tiny gain as a win. Without an interval, a 0.002 AUC gain is indistinguishable from noise.
- Reading offline gains as business gains. Report them as evidence the candidate is worth testing online.
A practical offline checklist
Before a candidate moves to shadow deployment, confirm the following:
- The candidate and baseline were scored on the same data, using the same code.
- The split respects time and the randomization unit.
- The improvement has an uncertainty interval, not just a point estimate.
- Key slices were checked and none regressed beyond an agreed tolerance.
- Every feature used is available at prediction time with the same definition online.
- Inference latency and memory were measured on representative hardware, even though offline evaluation does not cover load.
Item 6 is not strictly offline evaluation, but it is cheap, and it prevents wasting a shadow deployment on a model that is too slow to serve.
Exercise
A team trains a loan approval model on historical decisions and finds a candidate with a higher offline AUC than the current model. The historical data contains repayment outcomes only for applicants the current model approved. Name the limit of offline evaluation that applies here, explain why the offline AUC may be misleading, and name which rollout stage can measure the effect on the business outcome.
Show answer
The limit is selection bias (a feedback loop). The labels exist only for applicants the old model approved, so the candidate is scored on a population shaped by the old model. It may approve applicants who were never approved before, and their outcomes are unknown, so the offline AUC can be too optimistic or too pessimistic. A randomized A/B test measures the real effect, because applicants are assigned to each model at random and outcomes are observed for the decisions each model actually made. A shadow deployment alone would not help, since the candidate's decisions are never acted on and their outcomes are never observed.
Exercise
A paired bootstrap of the AUC difference between candidate and baseline returns a 95% interval of [-0.004, 0.011]. What can you conclude, and what should you do next?
Show answer
The interval contains zero, so the offline data does not show a reliable improvement or a reliable regression. The candidate may be slightly better, the same, or slightly worse. Reasonable next steps are to check whether the candidate has other benefits that justify testing, such as lower latency, or to examine important slices. If the team still wants to test it, move to shadow deployment and then an experiment with enough sample size to detect the effect that matters. Do not claim an improvement from the point estimate alone.