5 samples and 4 features, how to do direct linear discriminant analysisusing MATLAB package algorithm

5 次查看(过去 30 天)
5 samples and 4 features, how to do direct linear discriminant analysisusing MATLAB package algorithm?

回答(3 个)

Prateekshya
Prateekshya 2024-8-26
Hello Dayun,
You can use "fitcdiscr" function in MATLAB to perform Linear Discriminant Analysis. Here is a sample code:
% Sample data: 5 samples, 4 features
X = [
1.2, 2.3, 3.1, 4.0;
2.1, 3.4, 1.5, 2.3;
3.1, 2.1, 4.5, 1.2;
4.0, 3.3, 2.2, 3.1;
5.1, 2.9, 3.8, 4.2
];
% Class labels for each sample
Y = [1; 1; 2; 2; 1]; % Example labels, adjust according to your data
% Perform LDA
ldaModel = fitcdiscr(X, Y);
% Display the LDA model
disp(ldaModel);
% Predict class labels for the training data
predictedLabels = predict(ldaModel, X);
% Display predicted labels
disp('Predicted Labels:');
disp(predictedLabels);
Please follow the below link for more information on the same:
I hope this helps!

Dayun
Dayun 2024-8-26
Dear Prateekshya:
Thank you very much for your response.
Our data is an array (5×4) composed of 5 samples with 4 features. In addition, my objective is to do direct linear discriminant analysis(DLDA),not DLA with MATLAB package. Because previous reports demonstrated that Direct linear discriminant analysis (DLDA) is an improved feature extraction method that extends the application of the classical LDA algorithm in the context of small sample setting (SSS).
Anyway, I appreciate you very much for your kind help.
Best regards
Dayun
26-08-2024

Jaimin
Jaimin 2024-10-11
Whilefitcdiscr function is designed for classical LDA, you can use it with regularization to address small sample size issues, making it suitable for scenarios like DLDA.
Kindly refer to the following code snippet for further understanding.
X = rand(5, 4); % Replace with your 5x4 data matrix
y = [1; 1; 2; 2; 2]; % Replace with your class labels
% 'Delta' is the regularization parameter
ldaModel = fitcdiscr(X, y, 'DiscrimType', 'linear', 'Delta', 0.01);
% Obtain the coefficients for projection
W = ldaModel.Coeffs(1,2).Linear;
X_projected = X * W;
% Visualize the projected data
scatter(X_projected, zeros(size(X_projected)), 50, y, 'filled');
title('LDA Projected Data with Regularization');
xlabel('LD1');
grid on;
For more information on “fitcdiscr function kindly refer following MathWorks Documentation.
I hope this will be helpful.

Community Treasure Hunt

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

Start Hunting!

Translated by