Jimbo_ai
Jimbo_ai

Reputation: 167

Undefined function or variable 'resubPredict'. Why?

I have MATLAB R2015b and I am working on a Pattern Recognition project. I have loaded fisher iris data set. I have written the code below for k-NN classification:

rng default;
fold_number = 5;
indices = crossvalind('Kfold',species, fold_number);

val = 1:2:5; % for these small k values there will not be an important difference
         % regarding the cp ErrorRates. The difference is going to be
         % observable for val = 1:2:100, for example!!! But the
         % exercise asks only for k = 1,3,5.

err_arr = [];

for k=val

    cp = classperf(species); % Reinitialize the cp-structure!

    for i = 1:fold_number
        test = (indices == i); 
        train = ~test;
        class = knnclassify(meas(test,:),meas(train,:),species(train), k);
        %class = knnclassify(meas(test,2),meas(train,2),species(train), k); % To experiment only with the 2nd feature

        classperf(cp,class,test);
    end
    err_arr = [err_arr; cp.ErrorRate];
    fprintf('The k-NN classification error rate for k = %d is: %f\n', k,cp.ErrorRate);
end  

fprintf('\n The error array is: \n');
disp(err_arr);

fprintf('Program paused. Press enter to continue.\n');
pause

After that, I would like to plot the confusion matrix. So, I need this line of code:

[C,order] = confusionmat(species, predicted_species);

So, I have to find the predicted_species matrix. I have thought to write the below line of code about that:

predicted_species = resubPredict(class);

Here is the moment I am getting the on the title mentioned error and I do not know why, while resubPredict is a function supported by my MATLAB version.

Could anyone help me solve this problem?

Upvotes: 0

Views: 578

Answers (1)

Daniel
Daniel

Reputation: 36710

Take a look at the top of the documentation for resubPredict, there you will notice the line

Class ClassificationKNN

Meaning that the function can only be used with inputs of that type. In your case you are passing doubles.

You have to switch to the new interface, fitcknn instead of knnclassify

Upvotes: 1

Related Questions