leave-one-out using fitcdiscr

조회 수: 6 (최근 30일)
Lauren Mueller
Lauren Mueller 2019년 2월 1일
답변: Pratik 2024년 12월 12일
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일
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:

카테고리

Help CenterFile Exchange에서 Discriminant Analysis에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by