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

4 次查看(过去 30 天)
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?

回答(1 个)

Prantik Chatterjee
Prantik Chatterjee 2024-3-21
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.

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by