leave-one-out using fitcdiscr
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
As classify will soon disappear, I am motivated to learn fitcdiscr. I prefer leave-one-out crossval and typically use classify in the following manner to achieve leave-one-out:
load fisheriris %gives meas for sample, and species
group = NaN(150,1); %Create group to use instead of species
group(1:50)=1;
group(51:100)=2;
group(101:150)=3;
totalMeasurements = length(meas);
predClass = NaN(length(meas),1);
for i = 1:totalMeasurements;
%assemble training and test sets for loop
testingData = meas(i,:);
testingLabel = group(i);
%take whle data as training set
trainingData = meas;
trainingLabel = group;
%NaN out test sample
trainingData(i,:) = NaN;
trainingLabel(i) = NaN;
%remove NaNs from training set
bad = isnan(trainingLabel);
trainingLabel = trainingLabel(~bad);
trainingData = trainingData(~bad,:);
%use matlab classify function
predClass(i)= classify(testingData, trainingData, trainingLabel);
end
correct = predClass ==group;
percent_correct = sum(correct)/length(correct);
How do I use fitcdiscr to replace this? I've fooled around a bit with 'Leaveout' but I can't find good examples to follow. Thanks for your time!
0 commentaires
Réponses (1)
Pratik
le 12 Déc 2024
Hi Lauren,
The example given in 'fitcdiscr' shows the usage of this function over the 'fisheriris' dataset.
Please refer to the following documentation of same:
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!