A train-test split is the practice of dividing a labeled dataset into disjoint subsets, one used to fit a model and another held back to estimate performance on unseen data. In the management of training data for artificial intelligence, it is the most basic safeguard against overfitting, because a model that is scored on the same examples it learned from will almost always look better than it really is.
The scheme is often extended into a training-validation-test split, also called a holdout split, where a third subset supports model selection. The core principle stays the same: the test set must stay untouched until the final evaluation, so that the reported score reflects generalization rather than memorization.
How a train-test split estimates generalization
A train-test split works by treating the held-out portion as a stand-in for future data. The model sees only the training subset while its parameters are learned, and the test subset then provides an unbiased estimate of the generalization error, provided both subsets come from the same underlying distribution.
The estimate is only as good as the separation. If information from the test subset reaches training, for example through feature scaling fitted on the full dataset or duplicated records, the score becomes optimistic. This failure is called data leakage, and it is the most common reason why a model that excels offline disappoints in production.
The table below summarizes the role of each subset in a three-way split.
| Subset | Purpose | Used for decisions | Typical share |
|---|---|---|---|
| Training set | Fit model parameters | Yes, directly | 60-80% |
| Validation set | Tune hyperparameters and select models | Yes, indirectly | 10-20% |
| Test set | Report final performance once | No | 10-20% |
Choosing split ratios and sizes
Split ratios are a trade-off between learning and measuring. A larger training share gives the model more examples, while a larger test share narrows the confidence interval of the evaluation. Conventional ratios such as 80/20 or 70/15/15 are reasonable defaults for datasets of a few thousand to a few hundred thousand examples.
What matters for the test set is the absolute number of examples, not the percentage. With 100 million examples, a 1% test set still holds a million records, which is ample. With 500 examples, a 20% test set of 100 records gives an accuracy estimate with a standard error of several percentage points, and k-fold cross-validation is usually the better choice.
The following table gives practical starting points by dataset size.
| Dataset size | Common split | Recommended practice |
|---|---|---|
| Under 1,000 examples | Cross-validation plus small test set | Repeated k-fold to reduce variance |
| 1,000 to 100,000 | 70/15/15 or 80/10/10 | Stratified holdout split |
| 100,000 to 10 million | 90/5/5 | Fixed holdout with versioned indices |
| Over 10 million | 98/1/1 or smaller test share | Test set sized by required precision |
Splitting strategies for different data structures
The correct splitting strategy depends on how the data were generated. A plain random split assumes that examples are independent and identically distributed, an assumption that many real datasets violate because records are grouped, ordered in time or heavily imbalanced.
Stratified splitting preserves class proportions in every subset, which is essential when a rare class makes up a few percent of the data. Group splitting keeps all records of one patient, user or document in the same subset. Temporal splitting trains on the past and tests on the future, which mirrors how the model will actually be used.
| Strategy | When it applies | Risk it prevents |
|---|---|---|
| Random split | Independent, balanced records | Simple selection bias |
| Stratified split | Imbalanced class labels | Missing rare classes in the test set |
| Group split | Several records per entity | Identity leakage across subsets |
| Temporal split | Time-ordered data | Training on information from the future |
| Out-of-distribution split | Testing robustness to new domains | Overstated real-world accuracy |
Train-test split compared with cross-validation
A single holdout split and k-fold cross-validation answer the same question with different costs. The holdout approach trains the model once, which suits large datasets and expensive models such as large neural networks. Cross-validation trains the model k times on rotating partitions, which gives a lower-variance estimate but multiplies compute cost.
In practice, the two are combined: cross-validation runs on the training portion for model selection, and a final untouched test set confirms the chosen configuration. For large pretraining corpora, a holdout split is the only realistic option, and the main concern shifts to deduplication between subsets, because near-identical web pages can appear in both.
Common mistakes and how to avoid them
Most evaluation errors come from subtle contamination rather than wrong ratios. The table below lists frequent symptoms, their causes and the standard fixes.
| Symptom | Likely cause | Fix |
|---|---|---|
| Test score far above production score | Preprocessing fitted on all data | Fit scalers and encoders on training data only |
| Near-perfect accuracy on text or images | Duplicates across subsets | Deduplicate before splitting |
| Score drops sharply after deployment | Random split on time-ordered data | Use a temporal split |
| Results change with every run | Unfixed random seed or tiny test set | Fix the seed and enlarge the test set |
| Test score improves after many experiments | Repeated tuning on the test set | Tune on validation data only |
The last row describes test set overfitting, a slow form of leakage that also affects public benchmarks. Each time a team checks the test score and adjusts the model, the test set leaks a little information. A strict rule of evaluating on the test set once per final model protects the estimate.
Explained without jargon
A train-test split works like studying for an exam. A student learns from practice questions. The real exam uses new questions the student has never seen. If the exam simply repeated the practice questions, a high score would prove memory, not understanding.
Machine learning follows the same idea. Most of the data is used for learning. A smaller part is locked away. At the end, the model answers the locked questions, and that score shows how well it will handle new cases.
A typical use case
A hospital data team builds a model that flags chest X-rays with signs of pneumonia. The dataset holds 60,000 images from 18,000 patients, and many patients have several scans. A naive random split would place images of the same patient in both subsets, so the model could recognize the patient rather than the disease.
The team therefore applies a patient-level group split with stratification by diagnosis: 70% of patients for training, 15% for validation and 15% for testing. All image normalization statistics are computed on the training set only, and exact and near-duplicate images are removed before the split.
Hyperparameters are tuned on the validation set, and the test set is scored once. The final sensitivity is about four percentage points lower than an earlier random-split experiment had suggested, and that lower figure matches performance in a later pilot at a partner clinic, which confirms that the careful split produced a realistic estimate.