leave-one-out using fitcdiscr
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Pratik
on 12 Dec 2024 at 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:
0 Comments
See Also
Categories
Find more on Discriminant Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!