我有MATLAB R2015b,我正在开发模式识别项目。我已经加载了fisher虹膜数据集。 我已经为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版本支持的功能。
有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
请查看resubPredict
文档的顶部,您会看到该行
Class ClassificationKNN
意味着该函数只能用于该类型的输入。在你的情况下,你传递的是双打。
您必须切换到新界面fitcknn instead of knnclassify