How to using Linear Discriminant Analysis for classify training and testing dataset?

5 views (last 30 days)
I have a little confused about using Linear Discriminant Analysis (LDA) algorithm for classification after reading some articles.
1. Based on my understanding, for classification, training data and testing data should be separated. When reducing the dimension by LDA, I should combine training data and testing data together to reduce dimension, or just reduce training data dimension, and use eigenvector W to map testing data to lower dimension?
2. For standardized dataset mentioned in some article, I should standardize the whole data (training and testing) together, or just standardized the training data, and use the same scale mapping the testing data?

Answers (1)

Prantik Chatterjee
Prantik Chatterjee on 21 Mar 2024
1. Your second approach is the correct one. While reducing dimensionality using LDA, you should first fit the LDA model only on the training data and then use the transformation (eigenvector (W)) learned from the training data to map both the training and testing data to a lower dimension.
2. The same answer applies for data standardization as well. You should first standardize the training data and then use the standardization scale from the training data to scale the test data.
The reason for both of the above cases, is to avoid issues such as data leakage. Combining training and test data before any kind of transformation may lead to data leakage, where information from the testing data influences the model training process. This can result in overly optimistic performance metrics and a model that doesn't generalize well to unseen data.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!