Unit 6 of 8 · about 4 hours · derive

LDA, QDA and generative versus discriminative classifiers

LDA, QDA, naive Bayes and logistic regression all draw linear-or-quadratic boundaries from different assumptions. Seeing which assumption buys which boundary tells you what breaks first when the data disobeys.

You'll be able to

  • Derive the LDA discriminant from Gaussian class conditionals with shared covariance and show the boundary is linear.
  • Derive the QDA and Gaussian naive Bayes discriminants, and state the exact assumption that turns one into the other.
  • Contrast generative and discriminative fitting on parameter counts, small-sample behavior and robustness to violated assumptions.

Covers

LDA and QDA equations, assumptions and decision boundariesGenerative versus discriminative classification
1

Read

In this order, only the parts listed

0 of 5 done

  1. LDA for one and many predictorsAn Introduction to Statistical Learning with Python

    Chapter 4, Sections 4.4.1 to 4.4.2 (pp. 147-155): Bayes theorem for classification, Gaussian class conditionals, the shared-covariance assumption and the linear discriminant

  2. QDA and the analytical comparison of classifiersAn Introduction to Statistical Learning with Python

    Chapter 4, Section 4.4.3 (p. 156) for QDA, then Section 4.5.1 (pp. 161-164): the linear, quadratic and additive log-odds forms and which method nests inside which

  3. Generative versus discriminative classifiersTom Mitchell - Generative and Discriminative Classifiers: Naive Bayes and Logistic Regression

    Sections 1 (Bayes-rule learning and the parameter count), 2.1-2.2 (conditional independence and the naive Bayes derivation), 3.1 (Gaussian naive Bayes implies the logistic form) and 4 (discriminative versus generative, asymptotic identity, Ng and Jordan rates)

  4. LDA and QDA formulation and solversscikit-learn - linear models, discriminant analysis and naive Bayes

    Section 1.2.2 (Bayes rule, Gaussian class conditionals, QDA log-posterior, LDA linear form with coef_ and intercept_, and the QDA-with-diagonal-covariance equals GaussianNB note) and 1.2.5 (svd is the default solver)

  5. LDA and QDA lab on the Smarket dataAn Introduction to Statistical Learning with Python

    Linear Discriminant Analysis and Quadratic Discriminant Analysis sections: fits, posterior values and confusion matrices beside the logistic fit

2

Focus on

  • LDA log odds are linear in because the shared covariance cancels every quadratic term; QDA keeps one covariance per class, so its boundary is quadratic with cross terms.
  • Gaussian naive Bayes is QDA with diagonal class covariances. If each feature's variance is also shared across classes, it becomes LDA with a diagonal shared covariance (ISLP 4.5.1). Naive Bayes in general, with any per-feature densities, and QDA do not nest: naive Bayes log odds are additive in the features, while QDA's contain products of feature pairs.
  • Logistic regression and LDA posit the same linear log-odds form but fit it differently: LDA estimates class Gaussians and priors while logistic maximizes the conditional likelihood. Expect LDA to win when normality holds and logistic when it does not.
Common mistakes · 3
  • Fitting QDA with too few rows per class. Each class covariance comes from that class's rows alone, and with p or fewer rows per class (the class mean uses one) it is singular. Use QDA's reg_param or shrinkage with the eigen solver, or LDA with shrinkage.
  • Calling LDA parameter-free. It exposes no tuning knob by default but still estimates K means, a shared covariance and priors, which overfit small samples.
  • Assuming discriminative always wins with enough data. Logistic regression often has the lower asymptotic error under misspecification, but per Ng and Jordan naive Bayes approaches its own asymptote in order examples versus order for logistic regression, where is the number of features. So LDA and naive Bayes often win when training data are scarce.
3

Try it yourself

Closed-book, before checking anything

Write the LDA discriminant from the Gaussian log posterior. Build the two-Gaussian demo with default_rng(3): 40 standard normal points around [0,0], then 40 around [2,2]. Match sklearn LDA priors [0.5, 0.5], training score 0.95, coefficients [1.927, 2.229] and intercept -4.070.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Write the two-class LDA decision rule and name each estimated quantity.Answer

    Assign over of : class means, one shared covariance and priors. The -quadratic terms cancel because is shared, leaving a linear boundary.

  2. 2.When does QDA collapse to Gaussian naive Bayes, and when does Gaussian naive Bayes collapse toward LDA?Answer

    QDA restricted to diagonal class covariances is Gaussian naive Bayes. Gaussian naive Bayes whose per-feature variances are shared across classes is LDA with a diagonal shared covariance. General naive Bayes and QDA do not nest: one is additive, the other has pairwise products.

  3. 3.50 training points, 20 features, roughly Gaussian classes. LDA, QDA or logistic first?Answer

    LDA, possibly with shrinkage. QDA must estimate two 20-by-20 covariances from about 25 points each, and logistic fits 21 weights discriminatively with higher variance. Revisit logistic if normality is badly violated and more data arrives.

  4. 4.State the Ng and Jordan sample-complexity contrast and its practical consequence.Answer

    Naive Bayes approaches its asymptotic error in order training examples and logistic regression needs order , where is the number of features, not samples. So naive Bayes often wins on small training sets, while logistic regression, with its usually lower asymptotic error, wins once data are plentiful.

5

Practice

  • ISLP Lab 4.7.3-4.7.4: LDA and QDA on the Smarket data

    Linear Discriminant Analysis and Quadratic Discriminant Analysis sections: fits, posteriors and confusion matrices against the Section 4.7.2 logistic fit

    Record where QDA beats LDA and where it loses, and tie each case to the shared-versus-separate covariance assumption.

You're done when

You can write both discriminants from the Gaussian log posterior, predict the boundary shape from the covariance assumption, and call the likely winner from data geometry before fitting.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 4 more in the section

Also in this section

  • Dive into Deep Learning - linear models sliceD2L authors · required

    Use 3.1, 3.4, 3.6, 3.7, 4.1, 4.4, 22.7 and 22.9 for linear regression, generalization, weight decay, softmax, maximum likelihood and naive Bayes. Implement with NumPy first and use the PyTorch versions only as a differential reference.

  • Hands-On Machine Learning with Scikit-Learn and PyTorch - classification and linear modelsAurelien Geron (O'Reilly, 2025) · support

    Read the Chapter 3 and 4 sections each unit names, then run notebooks 03 and 04 for classification diagnostics, linear and polynomial regression, regularization and logistic regression. Recreate the target mechanism independently before inspecting worked exercise code.

  • NeetCode ML - linear-model closing drillNeetCode · support

    After the section gate, solve Gradient Descent, Sigmoid and ReLU, Softmax, Cross-Entropy Loss, Linear Regression Forward and Linear Regression Training cold. Repeat only failed items from a blank file with changed values.

  • Deep-ML - linear and probabilistic model problemsDeep-ML · support

    Use 15 Linear Regression Using Gradient Descent, 106 Train Logistic Regression with Gradient Descent and 140 Bernoulli Naive Bayes Classifier as unit checks after the local implementation passes. Their tests were read in review; each card states what they pin. The local implementation remains the evidence.