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?
댓글 수: 0
답변 (3개)
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!
댓글 수: 0
Jaimin
2024년 10월 11일
Hi @Dayun
While“fitcdiscr” 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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Discriminant Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!