Dataset Size and the Train, Validation and Test Split
Two practical questions come up at the start of almost every machine learning project: how big is my data, and how should I divide it up? This guide answers both with arithmetic you can check by hand, then tackles a third question people always ask: how much data do I need?
How much memory a table takes
For a table of numbers, the raw memory is simple multiplication:
values = rows x columns
bytes = values x bytes per value
A row is one example and a column is one feature. "Bytes per value" depends on how each number is stored:
- 8 bytes: a 64-bit floating-point number (often called float64), the usual default for decimals in Python.
- 4 bytes: a 32-bit float (float32), common in machine learning to save memory.
- 2 bytes: a 16-bit number.
- 1 byte: an 8-bit whole number from 0 to 255, which is how many grayscale image files store each pixel.
The Dataset Size Calculator does exactly this and then divides by 1,048,576 to give a figure it labels "MB". Note that unit: 1,048,576 bytes is 1,024 x 1,024, which is strictly called a mebibyte (MiB). Some tools use MB to mean 1,000,000 bytes instead, so the same table can be described as two slightly different sizes. The calculator rounds to 2 decimal places.
Worked examples
| Rows | Columns | Bytes each | Values | Bytes | Calculator shows |
|---|---|---|---|---|---|
| 10,000 | 20 | 8 | 200,000 | 1,600,000 | 1.53 MB |
| 1,000 | 4 | 4 | 4,000 | 16,000 | 0.02 MB |
| 150 | 4 | 8 | 600 | 4,800 | 0 MB (under 0.01 MB) |
| 60,000 | 784 | 1 | 47,040,000 | 47,040,000 | 44.86 MB |
The 150 x 4 table has the shape of the classic Iris flower dataset: 150 flowers, 4 measurements each, 3 kinds of iris. The 60,000 x 784 table has the shape of the MNIST handwritten digit training set: 60,000 images of 28 x 28 pixels, and 28 x 28 = 784, with one byte per pixel.
Two things to notice. First, most classroom datasets are tiny by computer standards: the Iris table would fit many thousands of times over in the memory of any phone. Second, these are raw numbers only. A file on disk adds headers, column names, separators or compression, and a program in memory adds its own overhead, so real sizes differ. Use the arithmetic to get the order of magnitude, not an exact file size.
How much data do you need?
There is no fixed rule like "you need 1,000 examples". The amount depends on:
- The task. Telling wide leaves from narrow ones is easy; telling apart 100 bird species from photos is hard.
- The model. A model with 5 parameters can be pinned down by far fewer examples than one with 109,386.
- How different the classes are. If the classes overlap a lot, the model needs many examples near the boundary to learn where it lies.
The honest way to find out is a learning curve: train on a small part of your training data, measure the score on the validation set, then repeat with more and more training data, and plot score against training-set size. The scikit-learn user guide describes a learning curve as showing "the validation and training score of an estimator for varying numbers of training samples", and as a tool "to find out how much we benefit from adding more training data" (scikit-learn: validation and learning curves). If the validation score is still rising at the right-hand end, more data is likely to help. If it has flattened out, more of the same data probably will not.
Better data usually beats simply more data
Adding rows helps only if the new rows teach the model something. Usually these matter more than raw size:
- Correct labels. A dataset where some labels are wrong teaches the model those mistakes. Fixing labels can be worth more than adding rows.
- Variety. Data that covers every kind of case the model will meet (different lighting, different seasons, different people) helps it on new examples. A million near-identical rows teach one thing a million times.
- Balance. If one class is very rare, a model can score well by ignoring it. Collecting more of the rare class often helps more than collecting more of everything.
- No duplicates across the split. Copies of the same example in both training and test sets make the test score look better than it is.
The guide to data and datasets covers labeling and cleaning step by step.
The train, validation and test split
You must never judge a model on the same examples it learned from, because it may simply have memorized them. So the rows are divided into three groups:
- Training set: the examples the model learns from.
- Validation set: examples used while you are still deciding things, such as which model to use, how many layers, or when to stop training. You look at the validation score many times.
- Test set: examples kept locked away until the very end. You use them once, to report how well your final choice works on data it has never influenced.
Why two held-out sets? Every time you choose something because it scored well on the validation set, you have tuned to that set a little. After enough choices, the validation score is slightly too optimistic. The untouched test set gives the honest final number.
How the calculator rounds the split
The calculator takes a training share and a validation share (out of 100) and works out:
- train = rows x training share / 100, rounded to the nearest whole row (halves round up)
- validation = rows x validation share / 100, rounded the same way, but never more than the rows left after training
- test = whatever is left
It refuses splits whose training and validation shares add up to more than 100, and the three counts never go negative.
| Rows | Split (train / validation) | Train | Validation | Test |
|---|---|---|---|---|
| 10,000 | 70 / 15 | 7,000 | 1,500 | 1,500 |
| 1,000 | 70 / 15 | 700 | 150 | 150 |
| 150 | 70 / 15 | 105 | 23 | 22 |
| 60,000 | 80 / 10 | 48,000 | 6,000 | 6,000 |
The 150-row case shows the rounding: 15 percent of 150 is 22.5, which rounds up to 23 for validation, leaving 22 for the test set.
Splitting well
- Shuffle first. If your table is sorted (all of Tree A, then all of Tree B), taking the first 70 rows for training would give the model only one class. Shuffle the rows with a fixed random seed so the split is repeatable.
- Keep the classes in proportion. With rare classes, make sure each set has some of every class. Splitting this way is called stratified splitting.
- Keep related examples together. If you photographed the same leaf three times, all three photos belong in the same set. Otherwise the test set contains near-copies of training examples, a form of data leakage explained in overfitting and underfitting.
- Small datasets give noisy scores. With 22 test rows, each mistake moves accuracy by about 4.5 points out of 100. Treat small-test results as rough.
Where this leads
Once you know how many training rows you have, you can work out how many steps each pass over the data takes and how long training might run. The guide to epochs, batches and training time picks up from here.