๐ Introduction
Linear Discriminant Analysis (LDA) is a supervised dimensionality reduction and classification algorithm that projects data onto a lower-dimensional space while maximizing the separation between different classes. Unlike Principal Component Analysis (PCA), which focuses on preserving variance, LDA focuses on improving class separability.
Information
๐ฏ Learning Objectives
- Understand Linear Discriminant Analysis.
- Learn the difference between PCA and LDA.
- Understand within-class and between-class scatter.
- Apply LDA for dimensionality reduction and classification.
๐ What is Linear Discriminant Analysis?
Linear Discriminant Analysis transforms the original feature space into a lower-dimensional space where observations belonging to different classes become as distinct as possible. It achieves this by maximizing the distance between class means while minimizing the spread of observations within each class.
| Characteristic | Linear Discriminant Analysis |
|---|---|
| Learning Type | Supervised |
| Main Objective | Maximize Class Separation |
| Uses Class Labels | Yes |
| Applications | Classification & Dimensionality Reduction |
๐ Key Concepts
| Concept | Description |
|---|---|
| Class Mean | Average feature vector for each class. |
| Within-Class Scatter | Variation among observations within the same class. |
| Between-Class Scatter | Variation between different class means. |
| Linear Discriminant | Projection direction that maximizes class separation. |
| Discriminant Components | New transformed features obtained after projection. |
๐ Within-Class Scatter Matrix
The within-class scatter matrix measures the spread of observations inside each class.
Where:
- Cแตข โ Class i.
- ฮผแตข โ Mean vector of class i.
- c โ Number of classes.
๐ Between-Class Scatter Matrix
The between-class scatter matrix measures how far apart different class means are.
Where:
- Nแตข โ Number of observations in class i.
- ฮผ โ Overall dataset mean.
Remember
๐ฏ LDA Optimization Objective
LDA finds projection directions that maximize the ratio of between-class scatter to within-class scatter.
The optimal projection vector maximizes this objective function.
โ๏ธ How LDA Works
Compute the mean vector for each class.
Calculate the within-class scatter matrix.
Compute the between-class scatter matrix.
Solve the generalized eigenvalue problem.
Select the discriminant vectors with the largest eigenvalues.
Project the original data onto the new discriminant space.
๐ณ LDA Workflow
๐ PCA vs LDA
| Feature | PCA | LDA |
|---|---|---|
| Learning Type | Unsupervised | Supervised |
| Uses Class Labels | No | Yes |
| Main Objective | Maximize Variance | Maximize Class Separation |
| Output Components | Principal Components | Linear Discriminants |
| Typical Use | Feature Extraction | Classification & Feature Extraction |
๐ Number of Components
Unlike PCA, the maximum number of linear discriminants is limited by the number of classes.
Where:
- C โ Number of classes.
Tip
๐๏ธ Important Hyperparameters
| Hyperparameter | Description |
|---|---|
| solver | Algorithm used to compute discriminants. |
| n_components | Number of discriminant components. |
| shrinkage | Regularization for covariance estimation. |
| store_covariance | Stores covariance matrix after training. |
๐ Evaluation Metrics
- Accuracy
- Precision
- Recall
- F1-Score
- ROC-AUC
- Confusion Matrix
- Class Separability
- Visualization Quality
- Downstream Model Performance
โ๏ธ Advantages and Limitations
- Excellent class separation.
- Reduces dimensionality while preserving discriminative information.
- Simple and computationally efficient.
- Works well when class distributions are approximately Gaussian.
- Improves many classification algorithms.
- Requires labeled training data.
- Assumes classes have similar covariance matrices.
- Assumes approximately Gaussian class distributions.
- Maximum components are limited to C โ 1.
- Less effective when assumptions are strongly violated.
๐ Real-World Applications
| Application | Purpose |
|---|---|
| ๐ฉบ Medical Diagnosis | Separate patients into diagnostic groups. |
| ๐ Face Recognition | Reduce image dimensions while preserving identity information. |
| ๐ง Spam Detection | Improve document classification. |
| ๐ณ Credit Risk Analysis | Classify loan applicants. |
| ๐งฌ Bioinformatics | Classify biological samples. |
| ๐ค Speech Recognition | Extract discriminative acoustic features. |
๐ป Practical Example
Linear Discriminant Analysis Using Scikit-learn
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.datasets import load_iris
# Load dataset
X, y = load_iris(return_X_y=True)
# Create LDA model
lda = LinearDiscriminantAnalysis(
n_components=2
)
# Transform data
X_lda = lda.fit_transform(X, y)
print("Transformed Shape:", X_lda.shape)
# Classification
predictions = lda.predict(X)
print("Predictions:")
print(predictions[:10])โ ๏ธ Common Mistakes
- Using LDA without labeled training data.
- Confusing Linear Discriminant Analysis with Latent Dirichlet Allocation (both abbreviated as LDA).
- Ignoring violations of Gaussian distribution assumptions.
- Expecting more than C โ 1 discriminant components.
- Applying LDA when classes are highly nonlinear and not linearly separable.