Contents
06Who wins? Small data versus big data
6.1The classic result
Which approach is better? Vapnik’s principle suggests the discriminative one: why solve the harder problem of modelling p(x\mid y)? Ng and Jordan (2002) compared naive Bayes and logistic regression, a generative–discriminative pair, and found two regimes. With n features:
- Asymptotically, the discriminative model wins. As the training set grows, logistic regression’s error converges to a value at most that of naive Bayes, \varepsilon(h_{\text{Dis},\infty})\le\varepsilon(h_{\text{Gen},\infty}), because it chooses the best linear boundary directly, while naive Bayes is tied to its independence assumption.
- The generative model gets there faster. Logistic regression needs on the order of n training examples to approach its asymptotic error, naive Bayes only on the order of \log n, because each of its parameters is a simple count estimated from all the data of one class.
In their words, “a generative classifier may also approach its (higher) asymptotic error much faster.” They confirmed this on 15 data sets from the UCI repository, averaging over 1000 random train/test splits: naive Bayes was usually better with few examples, and in most data sets logistic regression caught up and overtook it as the data grew.
The intuition is the bias–variance tradeoff of episode 2. Strong assumptions (independent features, Gaussian classes) are bias: they cost accuracy when they are wrong. But they also mean few, simple parameters, which is low variance: they need little data. The discriminative model makes weaker assumptions, so it has less bias and more variance.
6.2The digits experiment
Figure 8 repeats the experiment on the 4s and 9s of Example 4. For each training-set size, from 4 to 200 images, we drew random training sets, fitted Bernoulli naive Bayes (with add-one smoothing) and nearly unregularized logistic regression, and measured the error on 150 held-out images, averaging over 300 repetitions. Table 3 lists selected values.
| Training examples | 4 | 8 | 16 | 24 | 64 | 128 | 200 |
|---|---|---|---|---|---|---|---|
| Naive Bayes (generative) | 8.8\% | 5.2\% | 3.0\% | 2.5\% | 2.0\% | 1.8\% | 1.7\% |
| Logistic regression (discriminative) | 10.9\% | 6.8\% | 3.2\% | 2.5\% | 1.3\% | 0.9\% | 0.8\% |
With 4 examples naive Bayes makes 8.8\% errors and logistic regression 10.9\%; the curves cross at about 23 examples; with 200 examples logistic regression makes 0.8\% errors, less than half of naive Bayes’ 1.7\%. Naive Bayes levels off early because its independence assumption is wrong for pixels (neighbouring pixels are strongly correlated), and no amount of data fixes a wrong assumption.
6.3When the assumptions are right
If the generative assumptions hold exactly, the generative model is at least as good at every sample size, since it uses the extra information about p(x). Efron (1975) studied the case of truly Gaussian classes with a shared covariance and found that logistic regression is only moderately less efficient than normal discriminant analysis; as Ng and Jordan (2002) point out, his generative model had a full covariance matrix, which itself needs many examples, so it could not learn much faster than logistic regression.
6.4Rules of thumb
- Little labelled data, or a model you trust: a generative classifier (naive Bayes, Gaussian discriminant analysis).
- Plenty of data and accuracy is what matters: a discriminative classifier (logistic regression, gradient-boosted trees, neural networks).
- You need to generate data, detect unusual inputs, handle missing features or use unlabelled data: a generative model, whatever the data size (Section 7).
Pause and think. Why does adding more training data not help naive Bayes much beyond 100 examples in Figure 8?
Show the answer
Its error is limited by bias, not variance: the parameters are already well estimated, but the model assumes independent pixels, which is false. More data shrinks the variance of the estimates, not the error of the assumption.