Machine Learning / Training & Evaluation
Three splits and why the test set is sacred.
Reviewed by Yuvaraj
When you train a machine learning model, the one number you cannot trust is how well it scores on the data it learned from. A model can memorize its training examples and look brilliant, yet fall apart the moment it meets anything new. To measure real performance you have to hold data back and judge the model on examples it has never seen. That is the whole reason we split a dataset into three parts, training, validation, and test, each with a distinct job and a strict rule about how often you are allowed to look at it.
Each split answers a different question, and keeping them separate is what keeps your evaluation honest.
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
Every time a decision reacts to a score, that data leaks into the model through you. Validation data is meant to influence decisions, so its score is optimistic by design. The test set stays pristine precisely so it can act as an unbiased referee. Peek at it repeatedly and it quietly becomes a second validation set, and you lose your only trustworthy estimate.
Suppose you have 1,000 labeled examples and use a 70/15/15 split. First shuffle the rows (unless the data is a time series, see below), then slice:
| Split | Share | Count | Used for |
|---|---|---|---|
| Train | 70% | 700 | Fitting parameters |
| Validation | 15% | 150 | Tuning and model choice |
| Test | 15% | 150 | One final estimate |
You train on 700, compare configurations on 150, and, after everything is frozen, report accuracy on the last 150.
With only a few hundred examples, a single 150-row validation set is noisy: your estimate swings depending on which rows happened to land in it. k-fold cross-validation fixes this by rotating the validation role. Split the data (outside the test set) into equal folds, say folds of 200 rows each.
One round: hold out fold 1 as the validation set (200 rows), train on the other four folds (800 rows), and record the score. Then repeat with fold 2 held out, and so on for all five rounds. Averaging the five scores gives a far more stable estimate, and you still keep an untouched test set for the final check.
Common mistakes