leave-one-out using fitcdiscr

18 vues (au cours des 30 derniers jours)
Lauren Mueller
Lauren Mueller le 1 Fév 2019
Réponse apportée : Pratik le 12 Déc 2024
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!

Réponses (1)

Pratik
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:

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by