Library · Validation

The sealed test set, read once

A holdout sample gives an unbiased estimate once. Each time a decision is taken after looking at it, a little of it passes into the model. After enough rounds the reported score describes the holdout, not the future.

By , published

Definition

A sealed test set is a part of the data set aside before any modelling, and read a single time, after every choice has been frozen: features, model, settings, the metric and the threshold for success. Choices are made on the rest, by cross-validation or on a separate validation sample.

Dwork and co-authors studied the failure it prevents, often called adaptive overfitting: when each analysis depends on the results of the previous ones on the same sample, the usual guarantees no longer hold, even if each single step looks harmless.

Worked example

A classifier has a true accuracy of 70 %. Two hundred variants are produced, none better than the original. Each is scored on the same holdout of 500 rows and the best is kept, then scored again on fresh data.

import numpy as np

rng = np.random.default_rng(10)
true_accuracy, n_holdout, n_variants = 0.70, 500, 200

holdout_scores = rng.binomial(n_holdout, true_accuracy, n_variants) / n_holdout
best = holdout_scores.max()
fresh = rng.binomial(100_000, true_accuracy) / 100_000

print(f"true accuracy of every variant:           {true_accuracy:.3f}")
print(f"median variant on the holdout:            {np.median(holdout_scores):.3f}")
print(f"best of {n_variants} variants on the same holdout: {best:.3f}")
print(f"that variant on fresh data:               {fresh:.3f}")
print(f"sampling error of one read (2 sd):        +/- {2 * np.sqrt(0.7 * 0.3 / n_holdout):.3f}")

Output, produced by running the code above when this page was built:

true accuracy of every variant:           0.700
median variant on the holdout:            0.698
best of 200 variants on the same holdout: 0.742
that variant on fresh data:               0.702
sampling error of one read (2 sd):        +/- 0.041

The gain shown by the best variant, about four points, is entirely produced by the selection. It is as large as the sampling error of a single read, so it would pass as a real improvement, and it disappears on fresh data.

How to keep it sealed

  • Split first, before any exploration, and by time when the data are dated: the test window is the most recent one.
  • Write down what will be computed on the test set and what counts as success before opening it. A preregistered protocol with a public timestamp makes that verifiable.
  • Enforce it in code. A script that records each read and refuses a second one is more reliable than a rule in a document.
  • If the test fails, the test set is spent. A new attempt needs new data, or the result is reported as exploratory.

The cost is real: a sealed sample is data the model cannot learn from, and a single read has a sampling error that should be reported with it. Public benchmarks reused for years show the other side: Recht and co-authors rebuilt a test set for a well-known image benchmark and found accuracies several points lower.

In our work

Our test windows are read once, by a script that refuses to run if any file changed since the protocol was frozen. For our study on four public datasets the protocol was deposited before the read, and the read is logged.

References

  1. Dwork, C., Feldman, V., Hardt, M., Pitassi, T., Reingold, O., Roth, A. (2015). The reusable holdout: preserving validity in adaptive data analysis. Science, 349(6248), 636-638. doi:10.1126/science.aaa9375
  2. Recht, B., Roelofs, R., Schmidt, L., Shankar, V. (2019). Do ImageNet classifiers generalize to ImageNet?. Proceedings of the 36th International Conference on Machine Learning, PMLR 97, 5389-5400. proceedings.mlr.press/v97/recht19a.html
  3. Hewamalage, H., Ackermann, K., Bergmeir, C. (2023). Forecast evaluation for data scientists: common pitfalls and best practices. Data Mining and Knowledge Discovery, 37, 788-832. doi:10.1007/s10618-022-00894-5

Have a question like this one on your own data? Tell us what you need in a few lines.

Send us the brief

Related pages

  • Nested cross-validationWhen cross-validation is used for hyperparameter tuning, to pick the best of many settings, the winning score is no longer an honest estimate: it was selected for being high. Nested cross-validation scores the whole procedure, selection included.
  • The best of N trialsThe best result among many attempts carries a selection bias: it was kept because it was high. The more variants were tried, the better the best one looks, even when none has any real effect.
  • Walk-forward validationWalk-forward validation, also called rolling-origin evaluation, repeats one honest experiment: train on everything before a date, forecast what comes after, move the date forward. Shuffled cross-validation does not respect that order.
All library pages