Reputation: 13
The following code performs 10-fold cross-validation using linear discriminant analysis:
load fisheriris
indices = crossvalind('Kfold',species,10);
cp = classperf(species); % initializes the CP object
for i = 1:10
test = (indices == i); train = ~test;
class = classify(meas(test),meas(train),species(train));
% updates the CP object with the current classification results
classperf(cp,class,test)
end
cp.CorrectRate
How can this be modified to use fitcdiscr instead of classify on line 7? When I try, I get an error (Wrong number of arguments). I do not know what arguments are needed or not.
Upvotes: 0
Views: 830
Reputation: 21
fitcdiscr returns a model based on the training data with true labels. Therefore in order to obtain the predicted classes (class), we need to use the model method predict.
load fisheriris
indices = crossvalind('Kfold',species,10);
cp = classperf(species);
for i = 1:10
test = (indices == i); train = ~test;
Mdl = fitcdiscr(meas(train,:), species(train,:));
class = Mdl.predict(meas(test,:));
classperf(cp,class,test);
end
cp.CorrectRate
I tested this with the old function (classify) and the CorrectRate was the same.
Upvotes: 1