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

08Side by side: generative versus discriminative

8.1The comparison

GenerativeDiscriminative
Learnsp(x,y)=p(y)\,p(x\mid y), or p(x)p(y\mid x), or a map x\mapsto y
Classifies byBayes’ theorem, (2)reading off p(y\mid x)
Fittingjoint likelihood; often counts and averagesconditional likelihood; numerical optimization
Small databetter (Ng and Jordan: O(\log n) examples)worse (O(n) examples)
Large datalimited by its assumptionsusually more accurate
Can generateyesno
Missing features, outliersmarginalize; use p(x)no principled answer
Classic examplesnaive Bayes, Gaussian discriminant analysis (LDA, QDA), hidden Markov modelslogistic regression, support vector machines, decision trees
Modern examplesGPT, diffusion models, flow matching, GANs, variational autoencodersimage classifiers, click-through prediction
Table 4. Generative and discriminative models compared. Sources: Sections 2–7; Murphy (2022, §9.4), Ng and Jordan (2002).

8.2Common misconceptions

  • “Generative models are deep networks that make images and text.” Naive Bayes (1961) and linear discriminant analysis (1936) are generative models; GPT and diffusion models are just very large ones (Murphy, 2022, §9.4).
  • “Linear discriminant analysis is a discriminative model.” Despite the name, it fits a Gaussian to each class and is generative (Murphy, 2022, §9.1).
  • “Naive Bayes and logistic regression are the same model, since both are linear.” Same form \sigma(w^\top x+b), different objectives (9), different weights and different results (Example 4: 1.4\% against 0\% training error).
  • “Discriminative models are always more accurate.” Only with enough data; with a handful of examples the generative model often wins (Figure 8), and with correct assumptions it is never worse.
  • “A GAN is discriminative because it contains a discriminator.” The product is the generator, a generative model; the discriminator is a training signal, and at the optimum it is the Bayes posterior (20).
  • “A generative model’s posterior detects outliers.” The posterior divides p(x) away; use p(x) (Example 6).
  • “Flow matching paths are always straight.” The training lines (16) are straight; the learned flow is only nearly straight (Figure 7(b)), and a single step gives the data mean. Pairing noise with data without crossings makes it straight.