The three roles
- Training set: fits model parameters and preprocessing steps.
- Validation set: compares models, selects hyperparameters, and sets a decision threshold.
- Test set: gives a final estimate after those choices are complete.
A 70/15/15 split is one starting point, not a rule. With little data, cross-validation can make better use of training examples; keep a final test set if you need an independent final check. For a large dataset, a single held-out validation set may be adequate.
Read the visualization
The grid assigns each row to Train, Validation, or Test. Change the three proportions and the counts update; press Shuffle to see a different assignment. Try 70% Train, 15% Validation, and 15% Test, then reduce Test: more training data can help fit the model, but the final estimate becomes noisier when fewer examples remain for evaluation.
Shuffling is appropriate only when rows are exchangeable. It can place near-duplicates or related records in both train and test, making the evaluation too easy. For customers with repeated purchases, split by customer. For future prediction, train on earlier dates and test on later dates. Stratification can preserve class proportions in a random classification split, but it does not fix grouping or time leakage.
Split first, then fit transformations using training data only. A scaler, imputer, feature selector, or resampler must not learn from validation or test rows. In cross-validation, fit each transformation separately inside each training fold; a scikit-learn Pipeline helps enforce that order.
The test set is for the final report. Repeatedly checking it while changing features, thresholds, or models leaks information through those decisions. If you use its results to choose a change, it has become validation data; collect a new test set for an unbiased final estimate.
Worked example: predict next month’s churn
Suppose records include customers observed from January through December, and the goal is to predict January churn. Randomly splitting customer-month rows can put December for one customer in training and an earlier month for the same customer in test. It can also train on dates later than the period being evaluated.
Instead, define the prediction date and information available then. Train on earlier months and evaluate on a later time window. If the deployment goal is generalizing to entirely new customers, also hold out customers by group. The split should reproduce the deployment question; there is no universally correct ratio or shuffle setting.
Common mistakes with Train-Test Split
- Using the test set to tune: this makes the reported score optimistic.
- Preprocessing before splitting: test-set statistics enter training.
- Randomly splitting time series: future information can leak into the past.
- Ignoring repeated entities: related records across splits inflate performance.
- Treating one score as precise: small test sets have substantial sampling uncertainty.