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?
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!