leave-one-out using fitcdiscr

3 次查看(过去 30 天)
Lauren Mueller
Lauren Mueller 2019-2-1
回答: Pratik 2024-12-12,11:11
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!

回答(1 个)

Pratik
Pratik 2024-12-12,11:11
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:

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by