Training, Validation, and Test Sets: Protecting Honest Evaluation
📑 On this page
- A concrete example: selecting one model
- Training set
- Validation set
- Test set
- Random split
- Stratification
- Group split
- Time split
- Geographic or site split
- Leakage through preprocessing
- Duplicate examples
- Cross-validation
- Nested cross-validation
- Hyperparameters
- Early stopping
- Distribution shift
- Sample size
- Class imbalance
- Benchmark contamination
- Error analysis
- Govern the test set as a scarce resource
- Knowledge check
- The one idea to remember
A model can improve on the data used to guide every decision without improving on unseen real-world examples.
Separate datasets preserve different roles in development.
Training fits parameters, validation guides choices, and an untouched test set estimates final performance.
Repeatedly consulting the test set turns it into another validation set.
A concrete example: selecting one model
A team trains several models on the training set.
It uses validation results to choose:
- model family,
- features,
- regularization,
- threshold.
Only after decisions are fixed does it evaluate once on the test set for the final estimate.
Training set
Training data adjusts model parameters:
- weights,
- tree splits,
- embeddings.
The model may see examples many times.
Training performance measures fit, not generalization.
Validation set
Validation data guides:
- hyperparameters,
- feature selection,
- stopping,
- model comparison,
- threshold.
Every choice based on validation adapts indirectly to that set.
Test set
The test set estimates performance of the completed development process.
It should remain untouched by:
- feature decisions,
- model selection,
- error-driven redesign.
After heavy use, create a new independent evaluation.
Random split
A random split assigns examples to sets.
It works when examples are approximately independent and future use resembles the same distribution.
Many real datasets violate these assumptions.
Stratification
Stratified splitting preserves class proportions.
For rare fraud cases, a pure random split might leave too few positives in validation.
Stratify on relevant outcome or subgroup without leaking information.
Group split
Related examples should remain together.
If images of the same patient or events from the same customer appear in train and test, the model may memorize identity rather than generalize.
Split by patient, user, device, household, or source group.
Time split
For future prediction, train on earlier time and test on later time.
This reflects:
- drift,
- seasonal change,
- and data availability.
Randomly mixing future examples into training can leak temporal patterns.
Geographic or site split
To estimate transfer to a new hospital, store, or region, hold out entire sites.
A random within-site split answers an easier question.
Evaluation design should match deployment generalization.
Leakage through preprocessing
Preprocessing must be fit on training data only:
- mean and variance,
- vocabulary,
- imputation,
- feature selection,
- dimensionality reduction.
Fit the pipeline on train, then apply it unchanged to validation and test.
Duplicate examples
Near-duplicates across sets inflate performance.
Examples include:
- copied text,
- burst photos,
- same event exported twice,
- repeated records.
Deduplicate or group before splitting.
Cross-validation
Cross-validation rotates validation across several folds.
It provides a more stable estimate on limited data and supports hyperparameter selection.
Group and time constraints must still be respected.
Nested cross-validation
Nested cross-validation separates:
- inner model selection,
- outer performance estimation.
It reduces optimistic bias when data is small and many choices are tried.
It is computationally expensive.
Hyperparameters
Hyperparameters are chosen outside ordinary parameter fitting:
- tree depth,
- learning rate,
- regularization,
- architecture.
Searching many combinations can overfit validation.
Use bounded search and report the process.
Early stopping
Training can stop when validation performance no longer improves.
This makes validation part of training control. The final test remains independent.
Do not early-stop on test performance.
Distribution shift
All splits can be internally correct yet fail to represent deployment:
- new device,
- new market,
- changed policy,
- adversarial behavior.
Use representative external evaluation and post-deployment monitoring.
Sample size
Each set needs enough examples for stable metrics and important subgroups.
Rare outcomes may require longer collection or targeted sampling.
Report uncertainty intervals rather than one precise-looking number.
Class imbalance
Preserve enough positive and negative cases, then evaluate with suitable metrics.
Artificially balancing a test set changes prevalence and can distort precision. Reweight or recalculate to deployment prevalence when needed.
Benchmark contamination
Public test sets can leak into training through web data or repeated research tuning.
Performance then measures familiarity with the benchmark.
Use fresh private sets and contamination checks for important decisions.
Error analysis
Validation errors guide improvement.
After test evaluation, inspect failures for risk and future work, but recognize that redesign based on them consumes test independence.
Version evaluation datasets and model decisions.
Govern the test set as a scarce resource
Every time a team examines test results and changes the model, some information from the test set enters the development process. After enough rounds, the “unseen” test set effectively becomes another validation set.
Use a release protocol:
- define the metric and acceptance rule before opening test results,
- limit who can run final evaluation,
- record every evaluation and decision,
- avoid browsing individual test errors until the decision is made,
- and refresh the test set when repeated use has weakened its independence.
For high-stakes systems, maintain an additional locked audit set or run a prospective evaluation on future data. The goal is not secrecy for its own sake. It is preserving one credible measurement of how the chosen system behaves outside the choices that produced it.
Knowledge check
- What distinct role does each split serve?
- Why should related user examples stay in one set?
- How can preprocessing leak test information?
- When is a time split more honest than a random split?
- Why does repeated benchmark use weaken its evidence?
The one idea to remember
Training, validation, and test sets protect different stages of model development. Split by the real unit, time, and deployment boundary; fit preprocessing only on training data; and preserve untouched evaluation so performance evidence remains honest.