MoonSay /Tutorials/Machine Learning Interview #6
Contents
  1. 01Introduction
  2. 02Two ways to learn
  3. 03Bayes’ theorem
  4. 04What generative models create
  5. 05What discriminative models do
  6. 06Who wins? Small data versus big data
  7. 07Beyond accuracy
  8. 08Side by side
  9. 09Interview questions and model answers
  10. 10Summary
  11. References

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.

Learning curves for handwritten 4s and 9s (right: three examples of each, as the models see them). Naive Bayes is better up to about 23 training examples, logistic regression from then on. Mean test error over 300 random training sets. Data: Alpaydin and Kaynak (1998); computed for this tutorial, with the same numbers as the companion video.
Figure 8. Learning curves for handwritten 4s and 9s (right: three examples of each, as the models see them). Naive Bayes is better up to about 23 training examples, logistic regression from then on. Mean test error over 300 random training sets. Data: Alpaydin and Kaynak (1998); computed for this tutorial, with the same numbers as the companion video.
Try itWho wins with how much data?

The learning curves of Figure 8: mean test error on handwritten 4s and 9s for naive Bayes (generative) and logistic regression (discriminative). Choose the number of training examples.

Training examples48162464128200
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\%
Table 3. Mean test error on handwritten 4s and 9s (the data of Figure 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.