【发布时间】: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