How Much Data Do You Need?
Rules of thumb and formal approaches for estimating dataset size requirements. Why there is no universal answer, and how transfer learning changes the equation.
Understandably, this is the first question everyone asks, usually in the form "is 500 scans enough?" Nobody can answer that from the number alone. Five hundred scans is plenty for some tasks and hopeless for others.
There are really two questions hiding inside there. How much data do you need to train the model, and how much do you need to test it? The second has a proper statistical answer while the first has rules of thumb and one good experiment.
What you are counting
Don't count scans, count patients. A CT study with 300 slices is one patient's worth of information about how patients vary, and the slices are closely related to one another. Papers that report "40,000 images" from 150 patients have 150 of the important thing.
Count the rare class. A dataset of 10,000 studies with 80 positives is, for most purposes, a dataset of 80. The model has plenty of examples of normal and very few of what you are asking it to find, and your estimate of sensitivity will rest on however many of those 80 land in the test set (see 2.4 Class Imbalance).
And count sites, scanners and whatever other sources of variation the model will face. A thousand patients from one scanner is a lot weaker than five hundred from each of two machines.
What sets the size of the training set
The task. Segmentation needs the fewest cases, because every labeled pixel is a training signal and one outlined organ provides thousands of them. The original U-Net paper in 2015 trained on 30 annotated microscopy images. In the Medical Segmentation Decathlon, a public benchmark of ten tasks, the cardiac task has 20 training volumes, and methods do respectably on it. Classification is hungrier, because each case contributes a single label: one bit of information for an entire scan.
How subtle the finding is. Telling a normal chest film from a grossly abnormal one takes far less data than grading a subtle interstitial pattern. If residents need years to learn to see it, expect the model to need a lot of examples too.
How much the inputs vary. More scanners, protocols, body habitus and disease presentations mean more examples needed to cover them.
How noisy the labels are. Noisy labels can be partly compensated by volume, at a poor exchange rate, and only when the noise is random (see 2.1 Why Data Quality Matters More Than Model Complexity).
Where the model starts from. This is a standalone topic, covered below.
Some reference points
The landmark deep learning papers in medicine used very large datasets. Varun Gulshan and colleagues at Google trained their 2016 diabetic retinopathy model on about 128,000 retinal photographs. Andre Esteva and colleagues trained their 2017 skin cancer classifier on about 129,000 clinical images. The chest X-ray models of that period were trained on a public NIH set of about 112,000 films.
Those numbers frightened a lot of clinical researchers off, and they shouldn't have. They reflect what the authors could get, but the returns from the last hundred thousand were comparatively small. In 2019 Jared Dunnmon and colleagues at Stanford trained a model to sort chest radiographs into normal and abnormal using training sets of different sizes. With 2,000 films the AUC was 0.84. With 20,000 it was 0.95. With 200,000 it was 0.96. The first tenfold increase gave the majority of the benefit, while the second bought almost nothing.
For classical machine learning on tabular data the long-standing rule is ten outcome events per candidate predictor variable, which comes from simulation work on logistic regression by Peter Peduzzi and colleagues in the 1990s. So a model with eight predictors wants at least 80 patients who had the outcome, however many didn't. Richard Riley and colleagues have since published better methods for sizing a prediction model study, which account for the outcome rate and the expected performance, and if you are building a risk score you should use those instead of the rule of ten.
As rough orders of magnitude for imaging, with a pretrained starting point: segmentation of a well-defined structure can work from tens to a few hundred annotated studies. Classification of a reasonably visible finding wants hundreds to a few thousand cases per class. Subtle findings or many classes, more. Treat these as a guide to which ballpark you are in and nothing firmer.
Run the experiment: a learning curve
There is one way to find out if more data would help your project, try it out.
Take the data you have. Hold the test set fixed. Train the same model on 10% of the training data, then 25%, then 50%, then all of it, and plot test performance against training set size. This plot is a learning curve.
Performance tends to climb steeply at first and then flatten, roughly following a power law, so that each doubling of the data buys less than the one before. So have a look at the graph: if it is still pretty steep at 100%, more data will help, and you can extend the curve to estimate how much you would gain from doubling. If it has gone flat, more of the same data will not help, and the remaining error is coming from somewhere else: the labels, the variety of the data, or the limits of the task.
Junghwan Cho and colleagues did this in a 2015 study that asked the title question directly for classifying CT images by body region, fitting a curve to results at small training sizes and extrapolating to predict the size needed for a target accuracy. The same approach works on a pilot. Label 200 cases, draw the curve, and you have an evidence-based answer for the grant application.
One caution: the curve tells you about more data of the same kind. A flat curve on single-site data does not mean data from a second site would be useless. It would probably help generalization a great deal while leaving your single-site test score unchanged.
How pretraining changes things
A network trained from scratch has to learn everything from your data, starting with what an edge is. A pretrained network already knows about edges, textures and shapes, and your data only has to teach it your task. That cuts the requirement substantially, often by an order of magnitude.
Pretrained models used to come from ImageNet, a collection of everyday photographs. They now also come from self-supervised training on large medical collections (see 1.4 Foundation Models and Large Language Models in Clinical Research). The benefit is greatest when your labeled set is small. Maithra Raghu and colleagues showed in 2019 that on large medical datasets, ImageNet pretraining gave little improvement in final performance over training from scratch, though it got there faster. So pretraining is mostly a remedy for small data, which is the situation most clinical researchers are in. 3.3 Transfer Learning covers how it is done.
Augmentation also stretches a small dataset (see 2.5 Data Preprocessing and Augmentation), and so, with caveats, does synthetic data (see 2.8 Synthetic Data and Data Simulation). Neither adds new patients.
The test set: here you can calculate
The test set exists to estimate performance, and the precision of an estimate is ordinary statistics. You have done this calculation for other studies.
Say you expect a sensitivity of about 90% and you want the 95% confidence interval to be no wider than plus or minus 5 points. The usual formula for a proportion gives about 140 positive cases. Specificity of 90% to the same precision needs about 140 negatives. If you want plus or minus 3 points, it is closer to 400 of each.
Now account for prevalence. If you are sampling consecutive patients and 5% have the disease, 140 positives means about 2,800 patients. This is why test sets are often enriched with extra positives, which is legitimate as long as you say so and don't report predictive values as if the enriched prevalence were real.
Then account for subgroups. If you intend to report performance by sex, by scanner vendor and by site, and you should, each subgroup needs enough cases to produce an interval worth reading. Thirty positives in a subgroup gives an interval so wide that it rules out almost nothing.
A test set of 50 positives is common in published papers. Fifty positives with 45 detected is a sensitivity of 90% with a 95% interval running from roughly 78% to 97%. That is the difference between a useful tool and one that misses a fifth of cases, and the study cannot tell you which you have. 4.5 Statistical Significance, Confidence Intervals, and Sample Size for AI Studies has the methods.
Size the test set first, from the precision you need. Set it aside. What is left is your training data, and if that is not enough, you now know how much more to collect.
If you don't have enough
Narrow the question. A model that detects one finding in one modality in adults needs less than one that grades five findings across all comers.
Start from a pretrained model.
Spend on labels where they count. Active learning, where the model picks the cases it is least sure of for a human to label, gets more out of each hour of expert time than labeling at random (see 1.2 Supervised, Unsupervised, and Self-Supervised Learning).
Find collaborators. A second site adds cases and, more usefully, adds variety (see 2.6 Multi-Site and Multi-Device Data). Look for public datasets in your area too, for pretraining or for external testing.
Or consider that the project is a pilot. A study on 150 patients that reports honest intervals and says "this is feasible and here is the learning curve" is a legitimate paper and a good basis for funding the real one. A study on 150 patients that claims a clinical-grade model is neither.
Key takeaways
- There is no universal number. The task, the subtlety of the finding, the variety of the inputs, label noise and the starting model all change it.
- Count patients, count the rare class, and count sites. Slices are not patients.
- Segmentation can work from tens to hundreds of annotated studies. Classification usually needs hundreds to thousands per class, less with a pretrained model.
- A learning curve from a pilot tells you if more data of the same kind would help, and roughly how much.
- Pretraining reduces the labeled data needed, most of all when the dataset is small.
- The test set can be sized by calculation, from the confidence interval you need on sensitivity and specificity, in each subgroup you plan to report. Do that first.
What to read next
- 2.3 Data Annotation and Labeling for Clinical AI: what each of those cases costs to label
- 2.4 Class Imbalance: When Rare Conditions Dominate Your Research Question: when the count that counts is small
- 3.3 Transfer Learning: Standing on the Shoulders of Large Models: needing less data by starting further along
- 4.5 Statistical Significance, Confidence Intervals, and Sample Size for AI Studies: the test set calculation in full
This article is part of the AI in Clinical Research Knowledge Base.