What are training, validation, and test sets?
Training, validation, and test sets are three disjoint parts of a dataset, each with one job. The training set fits the model's parameters, the validation set chooses settings such as model size or learning rate, and the test set gives a single final estimate of performance on data the model has never influenced. Keeping them separate is what makes a reported score mean anything.
Every supervised learning project uses this split, from a scikit-learn regression to a large neural network. Kaggle competitions hide a private test set for the same reason, and public benchmarks such as ImageNet keep their test labels apart. When the split is done badly, through leakage, duplicates, or repeated tuning on the test set, a model can look excellent in the lab and fail in production.
Key ideas
- The training score always improves with complexity, so it cannot be used to choose a model.
- The training set fits parameters, the validation set chooses hyperparameters, and the test set reports the final score.
- All three sets must come from the same distribution, except in time series, where the test set comes from the future.
- Validation loss shaped like a U marks the move from underfitting to overfitting.
- Cross-validation reuses data for validation when samples are scarce.
- Any decision based on test results turns the test set into a second validation set.
Common questions
What is a good train/validation/test split ratio?
70/15/15 and 80/10/10 are common defaults for datasets of a few thousand to a few hundred thousand examples. What matters is the absolute size of the test set: with 1,000 test examples and 90% accuracy, the standard error is about √(0.9 × 0.1 / 1000) ≈ 0.95 percentage points. Very large datasets can give 98% or more to training and still have precise validation and test scores.
What is the difference between a validation set and a test set?
Both are held out from training, but the validation set is used many times to compare models and settings, while the test set is used once at the end. Because the validation set influences decisions, its score is biased upward. The test set's score is unbiased only if nothing was chosen based on it.
What is a stratified split?
A stratified split keeps each class's share the same in every set. With 5% positives, a random split of a small dataset can leave the test set with almost no positives, while stratification guarantees about 5% in each part. Libraries such as scikit-learn support it through a stratify argument.
Can I train on the validation set after tuning?
Yes. Once the hyperparameters are fixed, retraining on the training and validation data together usually gives a slightly better model, because it sees more examples. The test set is still kept out, and it scores this final retrained model.
Related explainers
- Overfitting & Underfitting — The bias-variance tradeoff and generalization
- Cross-Validation — K-fold, stratified, and leave-one-out evaluation
- Model Evaluation & Metrics — Precision, recall, F1, ROC curves, and regression metrics
- Hyperparameters — The knobs you tune before training begins
- Learning Curves — Diagnosing underfitting and overfitting from training size
- Bias-Variance Tradeoff — Why models underfit or overfit — the fundamental decomposition
References
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning", ch. 5
- Kaufman, Rosset, Perlich & Stitelman (2012), "Leakage in Data Mining: Formulation, Detection, and Avoidance", ACM TKDD
- Recht, Roelofs, Schmidt & Shankar (2019), "Do ImageNet Classifiers Generalize to ImageNet?", ICML
- Goodfellow, Bengio & Courville, "Deep Learning", ch. 5
Last updated