【问题标题】:Undefined function or variable 'resubPredict'. Why?未定义的函数或变量“resubPredict”。为什么?
【发布时间】:2016-05-06 01:47:54
【问题描述】:

我有 MATLAB R2015b,并且正在从事模式识别项目。我已经加载了费希尔鸢尾花数据集。 我已经为k-NN分类编写了以下代码:

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

之后,我想绘制混淆矩阵。所以,我需要这行代码:

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

所以,我必须找到 predict_species 矩阵。我曾想过为此编写以下代码行:

predicted_species = resubPredict(class);

这是我得到标题上提到的错误的那一刻,我不知道为什么,而 resubPredict 是我的 MATLAB 版本支持的函数。

谁能帮我解决这个问题?

【问题讨论】:

  • 请提供完整的错误信息和堆栈跟踪。

标签: matlab classification svm confusion-matrix


【解决方案1】:

查看resubPredict 的文档顶部,您会注意到这一行

类分类KNN

意味着该函数只能用于该类型的输入。在您的情况下,您正在通过双打。

你要切换到新界面,fitcknn instead of knnclassify

【讨论】:

  • 所以,要么我必须使用虚构更改我的代码,要么必须找到另一种方法来编写 resubPredict。 (我认为后者更有可能这样做。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
相关资源
最近更新 更多