How to perform linear discriminant analysis (LDA)?

35 次查看(过去 30 天)
I have a set data (100, 61), 100 is sampling point(observation), 61 is features. I have done data reducement using PCA before, but the plot of coeff 1 and 2 (PCA 1 and 2) has many overlap data. Hence I want to try LDA which has an euclidean distance between classes that expected can perform better than PCA. But I have difficulties to perform LDA using fisheriris function, I refer to this link
https://www.mathworks.com/help/stats/create-and-visualize-discriminant-analysis-classifier.html
but those only plot two feature (PL and PW). But in my case I need to plot 61 features in the same plot as perform in PCA as coeff1/coeff2. How do I can perform data projection using LDA(which considering euclidean distance) ?

回答(1 个)

Aditya
Aditya 2025-3-3
Hi Joynjo,
To perform Linear Discriminant Analysis (LDA) for dimensionality reduction and visualize the results, you can use MATLAB's fitcdiscr function. LDA is particularly useful for maximizing the separation between multiple classes. Here's how you can project your high-dimensional data onto a lower-dimensional space using LDA and visualize the results:
% Example data
% X is your data matrix (100 observations, 61 features)
% Y is your class labels vector (100 observations)
% Replace these with your actual data
% X = ...;
% Y = ...;
% Fit LDA model
ldaModel = fitcdiscr(X, Y);
% Transform data using LDA
[~, score] = predict(ldaModel, X);
% Plot the first two components
figure;
gscatter(score(:,1), score(:,2), Y);
xlabel('LDA 1');
ylabel('LDA 2');
title('LDA Projection');
legend('show');
grid on;
Here is a documentation link for the same:

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by