Mathwords logoMathwords

Training, Validation, and Test Data Sets — Definition & Example

Training, validation, and test data sets are three non-overlapping parts of one data set. You use the training set to fit a model, the validation set to choose between model versions, and the test set once at the end to estimate how well the final model works on new data.

Given a data set DD of nn observations, a train-validation-test split is a partition D=Dtrain∪Dval∪DtestD = D_{\text{train}} \cup D_{\text{val}} \cup D_{\text{test}} into pairwise disjoint subsets, usually made by random assignment. Model parameters are estimated only from DtrainD_{\text{train}}. Hyperparameters and model choice are selected by performance on DvalD_{\text{val}}. The error on DtestD_{\text{test}}, computed once for the selected model, serves as an estimate of its generalization error.

Worked Example

Problem: You have 2,000 labeled customer emails and want a model that flags spam. You split the data 70% / 15% / 15% into training, validation, and test sets. You train three candidate models. Their validation accuracies are Model A: 82%, Model B: 88%, Model C: 85%. You then run the chosen model on the test set, and it classifies 255 of the test emails correctly. What accuracy should you report?
Step 1: Find the size of each subset. Every email goes into exactly one of the three sets.
0.70(2000)=1400,0.15(2000)=300,0.15(2000)=3000.70(2000) = 1400, \quad 0.15(2000) = 300, \quad 0.15(2000) = 300
Step 2: Pick the model with the highest validation accuracy. Model B wins with 88%. The validation set has now been used to make a choice, so 88% is likely an optimistic estimate.
max⁡(82%, 88%, 85%)=88%  ⇒  Model B\max(82\%,\ 88\%,\ 85\%) = 88\% \;\Rightarrow\; \text{Model B}
Step 3: Evaluate Model B once on the 300 test emails, which played no part in training or selection.
255300=0.85=85%\frac{255}{300} = 0.85 = 85\%
Answer: Report a test accuracy of 85% for Model B. The 88% validation figure is biased upward because it was used to pick the winner.

Why It Matters

In machine learning and data science courses, this split separates a model that has memorized its data from one that generalizes. The same logic appears in statistics as out-of-sample validation. Picking the best of many models and reporting its in-sample score leads to inflated claims, much like running many hypothesis tests and reporting only the significant one.

Common Mistakes

Mistake: Checking test-set performance repeatedly and adjusting the model each time, or tuning the model on the test set.
Correction: Each look at the test set leaks information into your choices, so its error stops being an honest estimate. Do all tuning on the validation set and touch the test set only once, at the end.

Related Terms