5 samples and 4 features, how to do direct linear discriminant analysisusing MATLAB package algorithm
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
5 samples and 4 features, how to do direct linear discriminant analysisusing MATLAB package algorithm?
0 commentaires
Réponses (3)
Prateekshya
le 26 Août 2024
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 commentaires
Jaimin
le 11 Oct 2024
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 commentaires
Voir également
Catégories
En savoir plus sur Discriminant Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!