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

조회 수: 4 (최근 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.

카테고리

Help CenterFile Exchange에서 Discriminant Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by