Understanding the train / validation / test split calculator — concept and principle
This calculator turns percentages into actual sample counts for a training, validation and test split, and tells you how many batches (optimizer steps) one pass over the training set takes. Use it when preparing a dataset, setting up data loaders, or estimating how long an epoch will run.
How it is calculated
- Train count = round(N × train% ÷ 100).
- Validation count = round(N × validation% ÷ 100).
- Test count = N − train − validation. The test set receives whatever is left, so the three always add up to N exactly.
- Steps per epoch = ceil(N × train% ÷ 100 ÷ batch size). The last batch may be smaller than the others, so the count is rounded up.
The test percentage is not entered; it is implied as 100 − train% − validation%.
The principle
A model must be judged on data it has never seen. The training set is used to fit the weights; the validation set guides choices such as hyperparameters, architecture and early stopping; the test set is touched once at the end to give an unbiased estimate of real-world performance. Because you look at validation results repeatedly, the model gradually becomes tuned to that set, which is why a separate, untouched test set is needed. Rounding the first two counts and giving the remainder to test avoids losing or double-counting a sample.
Worked example
- Inputs: N = 10,000, train 70%, validation 15%, batch size 32.
- Train = round(10,000 × 0.70) = 7,000.
- Validation = round(10,000 × 0.15) = 1,500.
- Test = 10,000 − 7,000 − 1,500 = 1,500 (the implied 15%).
- Result: 7000 / 1500 / 1500.
- Steps per epoch = ceil(7,000 ÷ 32) = ceil(218.75) = 219; the last batch holds 24 samples.
How to read the result
Common splits are 70/15/15 and 80/10/10. With very large datasets (millions of samples), 1–2% each for validation and test is often plenty, because what matters is the absolute number of evaluation examples. With small datasets, a fixed split wastes data and makes estimates noisy; k-fold cross-validation is usually better. Steps per epoch × number of epochs gives the total optimizer steps, which you need for learning-rate schedules.
Common mistakes
- Splitting randomly when samples are not independent (several images of the same patient, time series), which leaks information into the test set.
- Not stratifying when classes are imbalanced, leaving a rare class absent from validation or test.
- Tuning repeatedly on the test set, which makes its score optimistic.
Frequently asked questions
Why does the test set get the remainder?
Rounding each part independently can make the total one off from N. Giving test the remainder keeps the sum exact.
Do I always need a validation set?
If you choose any setting by looking at results, yes, or use cross-validation. Otherwise you end up tuning on the test set.
Sources: T. Hastie, R. Tibshirani and J. Friedman, The Elements of Statistical Learning, 2nd ed., Springer, 2009, Section 7.2 and 7.10 · I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, MIT Press, 2016, Section 5.3