How much data is enough? This was the question for any statistical exercise, such as experiments, simulations, surveys. But nowadays, this is also the question for machine learning.
In case of statistics, sometimes this is easy. For example, flipping a biased coin with head-tail probabilities of and , the process of flipping times is modeled as binomial distribution. We expect to see number of heads, which for a 95% confidence interval. So to confirm the coin is fair ( which is the margin of error accepted), we need
Here we have a close form solution to find the number of data required to fit the model. In fact, for hypothesis testing in general, we have
However, it is not so easy to determine analytically the amount of data required for linear regression as well as other models. But we do have some common beliefs on how much data should be needed.
The classic problem of regression has the 1 in 10 rule, which says we need 10 cases for each predictor/feature used. But sometimes we may need 1 in 20 or even 1 in 50 in case of coefficient shrinkage.
In statistical learning theory, we have the concept of Vapnik-Chervonenkis dimension which states that the minimum number of samples need to train a binary function is expressed as a big-O notation:
- is the Vapnik-Chevronenkis dimension (a measure of complexity of a model, e.g., linear function can separate 3 arbitrary points but not 4 points in a 2D plane so the linear function has dimension 3)
- is the probability of failure
- is the learning error
But this is not a close form formula that can give guidance on the the sample size. I did not see any mention of the VC dimension outside academic discussion.
So how much data is needed for machine learning? Instead of explicitly giving out a number, a paper by Wang et al1 proposes to tell when to stop adding more data instead. Each sample is associates with a number of features. So the set of samples gives out a distribution of a particular feature and we can model the probability by the empirical distribution (possibly after kernel function is applied). Then, whether empirical distribution is similar to distribution can be determined by Kullback-Liebler divergence
The paper suggests to keep adding data until the distribution is stablised, i.e., when the KL divergence is getting small. This is the other way of saying we expect to see the law of diminishing return in the amount of data. However, one can also see that we may have many KL divergences to check – not only one for each feature we used, but also the joint distribution of any combination of features.
This gives us some insight on what we should expect: The amount of sample data and the accuracy of the learned model should exhibit power law relationship: . This is confirmed by some works2 but as we can expect, the power law will reach a plateau eventually. Especially in traditional problems, the plateau appears earlier than the deep learning problems, probably due to the complexity involved.
So here we come with some popular heuristics3: For classification problems, we need a minimum of 1000 samples per class, but bear in mind of the 1 in 10 rule. So if some feature is sparse, we need to collect more samples overall to compensate that. In harder problems, we may need up to 100K to 1 million samples. In case of computer vision, we are fortunate enough to have many pre-trained models available so we can use fewer than 1000 samples per class if we use one of those. Also generating variations from input (e.g., flipping and rotating images) is also common in computer vision that essentially provide more data to learn. This is an example of imbalance correction techniques (other examples: under- and over-sampling, ensemble learning) that can compensate for not enough training data.
But we should beware that more data is not always better. A discussion on Quora explained this well: A model that doesn’t perform well can due to high variance or high bias. The former is because the model used is too complicated4 compare to the data. We can tell if the model’s error on test set is significantly higher than the training set (i.e., overfitting). This is where more data can help. Or we can try with less number of input features (e.g., in case of NLP, do not use one-hot encoding for every word in the vocabulary). The latter is the converse, namely, the model is too simple to explain the data. This case, we need to extract more or better features5 from the data.
Wenshuo Wang, Chang Liu, and Ding Zhao, “How Much Data is Enough? A Statistical Approach with Case Study on Longitudinal Driving Behavior”. arXiv:1706.07637, 2017. https://arxiv.org/pdf/1706.07637.pdf ↩
See the references in https://towardsdatascience.com/how-do-you-know-you-have-enough-training-data-ad9b1fd679ee, especially Zhu et al., “Do we Need More Training Data?”, March 2015 (https://arxiv.org/abs/1503.01508) ↩
István Pilászy and Domonkos Tikk, “Recommending New Movies: Even a Few Ratings Are More Valuable Than Metadata”. In Proceedings of the third ACM conference on Recommender systems, pp 93-100. New York, New York, USA, October 23-25, 2009. https://doi.org/10.1145/1639714.1639731 ↩