Linear Discriminant Analysis is a generative model for classification. It is a generalization of Fisher’s linear discriminant. LDA works on continuous variables. If the classification task includes categorical variables, the equivalent technique is called the discriminant correspondence analysis.
The goal of Linear Discriminant Analysis is to project the features in higher dimension space onto a lower-dimensional space to both reduce the dimension of the problem and achieve classification.
- Generative Model that tries to estimate and
- Used for classification through dimension reduction
- Requires continuous variables
- Relies on normality assumption for and
- Requires homoscedasticity and full rank covariances
Consider a simple problem in which we want to decide whether a drug should be given to patients or not. Our features will be the gene expressions, and we will have 2 labels, for patients for which the drug worked, and for which it did not.
In PCA, we are interested in genes with the largest variations. In LDA, we are interested in maximizing the separability between the 2 known groups to make better decisions.
We’ll illustrate how we can improve the separability by this simple example. We suppose that we have 2 features, one for each gene. This means that we can plot the graph on a 2D plane.
How can we reduce the dimension of this problem to 1D ?
A bad way to approach this problem would be to project on the X-axis.
This would imply losing a lot of information from the Y-axis. what LDA does is that it projects the data onto a new axis in a way to maximize the separation between the 2 categories.
The projection, therefore, looks like this now, which is a good improvement :
How is this new axis created ?
- The new axis should maximize the distance between the two means :
- The new axis should minimize the variation, i.e scatter within each category
Both of the criteria can be optimized using the following ratio :
The numerator should ideally be large, and the numerator should be small. If we have 3 dimensions or more, the process remains the same!
If we have 3 categories, the process pretty much remains the same. We compute the distance to a central point and maximize the distance with respect to it.
The new criteria is now :
Another thing that changes when adding this class is that we do now project on a new place, not a single axis. This is because the 3 central points for each category define a plane. We can now build new X and Y axis, optimized for classification.
Being able to draw the data on 2 axes is interesting if we have an initial high dimensional problem. Once we redefined our X and Y axis, it is really easy to apply fit a linear regression on top! And voilà, this is the LDA!
Back to our example with 2 classes. We would like to find the two underlying marginal distributions.
We’ll define the distributions of the 2 classes :
- distribution of the class 1
- distribution of the class -1
We can plot the probability densities :
The LDA relies on some strong hypothesis which we’ll explicit now.
Gaussian marginal distributions
LDA should be used when the covariance matrices are equal among the 2 classes :
To understand the intuition behind how LDA works, we can define a likelihood ratio :
Using Bayes’ theorem :
We can re-define as and as the prior probability .
We can easily isolate the prior probability :
How do we find the parameters of the model? How does the learning process work?
If , then . This means that :
Which can be re-written as :
This should remind you of the ratio to optimize we defined in the first part of the article! The parameter and are the parameters of the linear regression fitted on the modified axis plane.
The question now becomes : How can we estimate and ? By Maximum Likelihood, we obtain the following :
We then simply replace those values to find and .
Quadratic Discriminant Analysis (QDA)
So far, we supposed that the class variance had to be the same : . If we relax this hypothesis, we obtain the QDA, where .
Conclusion : I hope this introduction to LDA was helpful. Let me know in the comments if you have any question.
Like it? Buy me a coffee