You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linear Discriminant Analysis (LDA) is a dimensionality reduction technique commonly used for supervised classification problems. The goal of LDA is to project the dataset onto a lower-dimensional space while maximizing the class separability.
LDA is very similar to Principal Component Analysis (PCA), but there are some important differences. PCA is an unsupervised algorithm, meaning it doesn't need class labels $y$. PCA's goal is to find the principal components that maximize the variance in a dataset. LDA, on the other hand, is a supervised algorithm, which uses both the input data $X$ and the class labels $y$ to find linear discriminants that maximize the separation between multiple classes.
LDA can be performed in 5 steps:
Compute the mean vectors for the different classes from the dataset.
Compute the scatter matrices (in-between-class and within-class scatter matrices).
Compute the eigenvectors and corresponding eigenvalues for the scatter matrices.
Sort the eigenvectors by decreasing eigenvalues and choose k eigenvectors with the largest eigenvalues.
Use this eigenvector matrix to transform the samples onto the new subspace.
Computing the mean vectors
First, calculate the mean vectors for all classes inside the dataset.
$$m_i = \frac{1}{n_i} \sum_{i=1}^{n_i} x_i$$
Computing the scatter matrices
After calculating the mean vectors, the within-class and between-class scatter matrices can be calculated.
Within-class scatter matrix $S_W$
$$S_W = \sum\limits_{i=1}^{c} S_i$$
where $S_i$ is the scatter matrix for a specific class
Select linear discriminants for the new feature subspace
After calculating the eigenvectors and eigenvalues, we sort the eigenvectors from highest to lowest depending on their corresponding eigenvalue and then choose the top $k$ eigenvectors, where $k$ is the number of dimensions we want to keep.
Transform data onto the new subspace
After selecting the $k$ eigenvectors, we can use the resulting $d \times k$-dimensional eigenvector matrix $W$ to transform data onto the new subspace via the following equation: