Machine Learning

Linear Discriminant Analysis

Find a class-aware projection by balancing mean separation against within-class covariance.

By Riano · Published · Updated · Report a correction

Linear Discriminant Analysis

Linear Discriminant Analysis (LDA) is a method to find a linear combination of features that characterizes or separates two or more classes of objects or events. The resulting combination may be used as a linear classifier or for dimensionality reduction.

Worked Example

Consider two Gaussian classes with equal prior probabilities:

  • Class 0: mean μ0 = (-1, 0)
  • Class 1: mean μ1 = (1, 0)
  • Common covariance matrix: Σ =
    [1, 0.5]
    [0.5, 1]

This corresponds to a correlation of 0.5 with no shrinkage. To find the decision boundary, we first determine the Fisher direction vector w, which maximizes the separation between the projected means while minimizing the within-class variance.

w is proportional to Σ-1(μ1 - μ0).

  1. Calculate det(Σ) = 1 - 0.52 = 0.75.
  2. Calculate Σ-1 = (1/0.75) * [[1, -0.5], [-0.5, 1]].
  3. The difference in means is μ1 - μ0 = (2, 0).
  4. Multiplying gives Σ-1 * (2, 0) = (1/0.75) * (2, -1).
  5. Normalizing this vector (with a positive x sign) gives w ≈ (0.894, -0.447).
  6. Fisher separation J = 4 / (1 - 0.52) = 5.333333333333333.
  7. For a probe point x = 1, y = 0, the log likelihood ratio is 2*(1 - 0.5*0) / (1 - 0.52) = 2.6666666666666665. The threshold is 0, so the expected result is predicted class 1.

Experiment

Try the Linear Discriminant Analysis module.

  1. Set Correlation to 0.5.
  2. Set Shrinkage to 0.
  3. Set Probe x to 1 and Probe y to 0.
  4. Observe the Fisher separation (5.333) and log likelihood ratio (2.667). The direction vector is normalized. The predicted class is 1.
  5. Change Probe x to 0 and Probe y to 1. The log likelihood ratio becomes -1.333, and the predicted class changes to 0.
  6. Change Correlation to -0.5. The direction vector's y component flips sign, and the covariance ellipses tilt in the opposite direction.
  7. Set Shrinkage to 1. The covariance is shrunk to the identity matrix, turning the ellipses into circles and decoupling the dimensions.

Limitations

LDA assumes that the classes are normally distributed and share the same covariance matrix. When these assumptions are violated (e.g., heavily skewed data, or different covariances requiring Quadratic Discriminant Analysis), LDA may perform poorly. In this specific module, the threshold is fixed at 0 for equal priors.

References

These references provide the theoretical foundations for the assumptions and formulations used in LDA.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Linear Discriminant Analysis module.

Try Linear Discriminant Analysis on Riano →

More in Machine Learning