Part IV — Supervised Learning: Regression & Linear Classifiers · Chapter 9

Linear Discriminant Analysis (LDA)

Hook

PCA finds the direction of maximum variance — but it doesn't know or care about class labels. Two clusters can overlap completely along PCA's favorite direction while sitting far apart along some other direction PCA never considers. What if you do have labels, and want the direction that best tells the classes apart?

Intuition
● class A● class B
separation score = 10.00

Class B's mean never moves. Shrink its spread and watch the dashed projection axis rotate — and the separation score climb — purely because the classes have gotten individually tighter, not because they've moved any further apart.

Formalize

Fisher's LDA looks for the direction w\mathbf{w} that maximizes the ratio of between-class separation to within-class spread once every point is projected onto it:

w=SW1(μAμB)\mathbf{w} = S_W^{-1}(\boldsymbol{\mu}_A - \boldsymbol{\mu}_B)
  • μA,μB\boldsymbol{\mu}_A, \boldsymbol{\mu}_B — the mean position of class A and class B.
  • SWS_W — the within-class scatter: how spread out each class is around its own mean, summed across both classes. Small SWS_W means tight clusters.
  • SW1S_W^{-1} — inverting it means directions where the classes are naturally tight get amplified more than directions where they're naturally spread out.
  • w\mathbf{w} — the resulting direction: not just "toward the other class's mean," but rescaled by how reliable each axis is.
  1. Between-class scatter is the mean gap, squared

    SB=(μAμB)(μAμB)S_B = (\boldsymbol{\mu}_A-\boldsymbol{\mu}_B)(\boldsymbol{\mu}_A-\boldsymbol{\mu}_B)^\top — large when the class means are far apart, independent of how tight or loose either cluster is.

  2. Without S_W^-1, this would just be PCA on the mean difference

    Projecting onto the raw mean-difference vector alone ignores each class's own shape — a direction where both classes happen to be tightly packed is far more useful for separating them than a raw "toward the other mean" heading.

  3. A degenerate S_W (perfectly collinear class spread) breaks the inverse

    If both classes' points fall on a single shared line, SWS_W becomes singular and SW1S_W^{-1} doesn't exist — the same failure mode ridge regression exists to patch, one chapter over.

Play
● class A● class B
raw distance between means = 4.47 (constant) — LDA separation score = 8.89

The raw Euclidean distance between the two class means never changes as you move the slider — only class B's own spread does. Yet the LDA separation score moves a lot: distance between means alone isn't what makes classes separable, distance relative to how tight each class is does.

Worked example

Class A: (1,2),(3,2)(1,2), (3,2), mean (2,2)(2,2). Class B: (6,3),(6,5)(6,3), (6,5), mean (6,4)(6,4).

  1. Within-class scatter for each class

    Each class's scatter is the sum of (pointmean)(pointmean)(\text{point}-\text{mean})(\text{point}-\text{mean})^\top over its points.

    • Class A: deviations (1,2)(2,2)=(1,0)(1,2)-(2,2)=(-1,0) and (3,2)(2,2)=(1,0)(3,2)-(2,2)=(1,0). Both outer products give [1000]\begin{bmatrix}1&0\\0&0\end{bmatrix}, summing to SA=[2000]S_A = \begin{bmatrix}2&0\\0&0\end{bmatrix}.
    • Class B: deviations (6,3)(6,4)=(0,1)(6,3)-(6,4)=(0,-1) and (6,5)(6,4)=(0,1)(6,5)-(6,4)=(0,1). Both outer products give [0001]\begin{bmatrix}0&0\\0&1\end{bmatrix}, summing to SB=[0002]S_B = \begin{bmatrix}0&0\\0&2\end{bmatrix}.

    Summed: SW=SA+SB=[2002]S_W = S_A+S_B = \begin{bmatrix}2&0\\0&2\end{bmatrix} — a clean multiple of the identity, so SW1=[0.5000.5]S_W^{-1} = \begin{bmatrix}0.5&0\\0&0.5\end{bmatrix}.

  2. The mean-difference vector

    μAμB=(26,24)=(4,2)\boldsymbol{\mu}_A - \boldsymbol{\mu}_B = (2-6,\, 2-4) = (-4,-2).

  3. The LDA direction, and the resulting separation

    w=SW1(4,2)=(0.5(4), 0.5(2))=(2,1)\mathbf{w} = S_W^{-1}(-4,-2) = (0.5(-4),\ 0.5(-2)) = (-2,-1). Projecting each point onto w\mathbf{w} (raw dot product):

    • Class A: (2)(1)+(1)(2)=4(-2)(1)+(-1)(2)=-4 and (2)(3)+(1)(2)=8(-2)(3)+(-1)(2)=-8 — mean 6-6
    • Class B: (2)(6)+(1)(3)=15(-2)(6)+(-1)(3)=-15 and (2)(6)+(1)(5)=17(-2)(6)+(-1)(5)=-17 — mean 16-16

    A gap of exactly 1010, with each class landing tightly around its own mean.

Checkpoint

Decrease class B's spread until the separation score climbs above 14 — without moving either class's mean at all.

● class A● class B
separation score = 8.22
Move the spread slider to try it
Summary
w=SW1(μAμB)\mathbf{w} = S_W^{-1}(\boldsymbol{\mu}_A - \boldsymbol{\mu}_B)

LDA's direction isn't just "point from one class mean toward the other" — it's that heading, corrected by SW1S_W^{-1} so that directions where the classes are naturally tight count for more than directions where they're naturally spread out. That's what makes it a classification-aware projection, where PCA is not.