Classification: Logistic Regression and LDA
Modeling a probability instead of a mean - the logit link and its MLE, linear discriminant analysis, and how the two linear boundaries relate.
Leads to: Logistic loss reappears as the boosting surrogate and in neural-network output layers.
Learning Objectives
Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.
- Formulate logistic regression via the logit link and write its log-likelihood.
- Derive the logistic gradient and explain why the fit needs iterative optimization.
- State the LDA model assumptions and derive its linear discriminant boundary.
- Compare logistic regression and LDA on assumptions, robustness, and boundary shape.
- Explain why accuracy is a misleading metric for rare-event financial classification.
Key Vocabulary
- Logit / log-odds
- The transform \(\log\frac{p}{1-p}\) mapping a probability to the whole real line; logistic regression makes it linear in \(x\).
- Sigmoid
- The inverse logit \(\sigma(z)=1/(1+e^{-z})\), squashing a linear score into \((0,1)\).
- Log-likelihood (Bernoulli)
- \(\ell(\beta)=\sum_i[y_i\log p_i+(1-y_i)\log(1-p_i)]\); concave, so its maximizer is unique.
- LDA
- Linear Discriminant Analysis: Gaussian class densities with a shared covariance, giving a linear decision boundary.
- Decision boundary
- The set where two classes are equally probable; linear for logistic and LDA, quadratic for QDA.
- Bayes classifier
- Assign to the class with the highest posterior \(\Prob(G=k\mid x)\); the theoretical error-minimizing rule.
- Class imbalance
- When one class is rare (defaults, crashes); accuracy is dominated by the majority and hides model quality.
Intuition & Motivation
LDA reaches a linear boundary from the opposite direction. Assume each class is a Gaussian blob with the same shape (shared covariance), differing only in center. The optimal boundary between two equal-shape Gaussians is a straight line. Logistic regression models the boundary directly; LDA models the two clouds and derives the boundary. When the Gaussian assumption holds, LDA is more efficient; when it fails (fat tails, outliers), logistic regression is more robust.
Logistic regression: modeling the log-odds
For a binary label \(y\in\{0,1\}\) we posit \(\Prob(y=1\mid x)=p(x)=\sigma(x^\top\beta)\), equivalently a linear logit:
Under independence the Bernoulli log-likelihood is \(\ell(\beta)=\sum_i\big[y_i\log p_i+(1-y_i)\log(1-p_i)\big]\) with \(p_i=\sigma(x_i^\top\beta)\).
Because \(-\ell\) is convex (the Hessian \(-X^\top W X\preceq0\)), the maximizer is unique when it exists; it fails to exist only under perfect separation, where coefficients diverge - a signal to regularize.
Linear discriminant analysis
LDA models each class density as Gaussian with a shared covariance: \(x\mid G=k\sim\Normal(\mu_k,\Sigma)\), with priors \(\pi_k\). By Bayes' rule the log-posterior-odds between classes \(k\) and \(\ell\) is linear in \(x\) because the quadratic \(x^\top\Sigma^{-1}x\) terms cancel:
The boundary \(\{\delta_k=\delta_\ell\}\) is a hyperplane. If instead each class has its own covariance \(\Sigma_k\), the quadratic terms survive and you get QDA with a curved boundary - more flexible but more parameters to estimate.
| Aspect | Logistic regression | LDA |
|---|---|---|
| Models | the boundary \(\Prob(y\mid x)\) directly | the class densities \(\Prob(x\mid G)\) |
| Assumes Gaussian \(x\) | No | Yes (shared \(\Sigma\)) |
| Fit | MLE / IRLS (iterative) | Plug in means and pooled covariance (closed form) |
| Robust to outliers / fat tails | More | Less |
| Efficiency if Gaussian holds | Slightly lower | Higher |
Interactive: logistic score and one Newton step
- Fitting ordinary least squares to a 0/1 label; predicted ‘probabilities’ then fall outside \([0,1]\) and the error variance is wrong.
- Interpreting a logistic coefficient as a probability change; it is a change in log-odds, and \(e^{\beta_j}\) is an odds ratio.
- Reporting accuracy on an imbalanced problem (1% defaults): predicting ‘never’ scores 99% accuracy and is useless.
- Using LDA when classes are clearly non-Gaussian or have very different covariances - QDA or logistic is safer.
- Ignoring perfect (quasi-)separation, which sends logistic coefficients to infinity; regularize or add a prior.
- For rare events use ranking metrics (AUC), precision/recall, log-loss, or profit curves - not raw accuracy.
- Calibrate probabilities before betting sizes on them; a good ranker can still be miscalibrated.
- Penalized (ridge/lasso) logistic regression handles separation and high dimension gracefully - the same \(\lambda\) idea as 11.4.
- LDA doubles as a supervised dimension-reduction tool (Fisher's discriminant directions), useful before plotting or clustering.
Knowledge Check
Practical Exercise
A model flags market crashes; crashes are 2% of days. Your classifier attains 98% accuracy. (a) Show this can be achieved trivially. (b) Define precision and recall and explain what they reveal here. (c) Why might log-loss or AUC be better objectives, and how does class imbalance interact with the logistic threshold?
(a) Predict ‘no crash’ every day: you are right on 98% of days, so 98% accuracy is the no-skill baseline. Accuracy is uninformative when one class dominates.
(b) Precision = TP/(TP+FP) = of the days you flagged, how many crashed; Recall = TP/(TP+FN) = of the crashes, how many you caught. A useful crash detector needs decent recall (catch crashes) at acceptable precision (few false alarms); the trivial classifier has recall 0.
(c) Log-loss rewards calibrated probabilities and heavily punishes confident wrong calls; AUC measures ranking skill independent of the threshold and of the base rate. With imbalance, the default 0.5 logistic threshold is usually wrong - you tune the threshold (or reweight classes) to trade precision against recall according to the cost of a missed crash versus a false alarm.
Lesson Summary
Formula Sheet Additions
- Did I model a probability (logit) rather than regress a 0/1 with OLS?
- Did I report a threshold-free / imbalance-aware metric (AUC, log-loss), not raw accuracy?
- Did I check for separation and regularize if coefficients diverged?
- Is the Gaussian/shared-covariance assumption plausible before I trust LDA?
Retrieval Practice
Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.
A: \(X^\top(y-p)=0\) with \(p=\sigma(X\beta)\); nonlinear in \(\beta\), so solved by Newton/IRLS despite convexity.
A: A covariance \(\Sigma\) shared across classes makes the quadratic terms cancel; class-specific \(\Sigma_k\) (QDA) restores curvature.
A: A trivial majority predictor scores near the base rate (e.g. 98%); use AUC, precision/recall, or log-loss that reflect the costs of each error.
Flashcards
Click to flip. These feed the site-wide spaced-repetition queue.
Completion Checklist
- I can explain the core ideas in my own words
- I worked the derivations/examples by hand
- I completed the interactive workbench(es)
- I passed the knowledge check
Source References
This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.
- The Elements of Statistical Learning (Hastie, Tibshirani & Friedman, 2nd ed.) current - ESL 4 - Ch. 4: linear methods for classification - LDA/QDA, logistic regression, separating hyperplanes.
- Probability: Theory and Examples (Rick Durrett, 5th ed.) current - Durrett 4 - Conditional distributions and Bayes rule underlying the posterior class probabilities.