【发布时间】:2016-03-15 01:42:28
【问题描述】:
这是我的一对一代码。此代码不是由@amro 编写的。我不明白为什么会这样。当我学习代码时,一切看起来都很简单。请帮我修复它。我正在使用 matlab2014a。
代码:一对一
%# load dataset
load fisheriris
[g gn] = grp2idx(species); %# nominal class to numeric
%# split training/testing sets
[trainIdx testIdx] = crossvalind('HoldOut', species, 1/3);
pairwise = nchoosek(1:length(gn),2); %# 1-vs-1 pairwise models
svmModel = cell(size(pairwise,1),1); %# store binary-classifers
predTest = zeros(sum(testIdx),numel(svmModel)); %# store binary predictions
%# classify using one-against-one approach, SVM with 3rd degree poly kernel
for k=1:numel(svmModel)
%# get only training instances belonging to this pair
idx = trainIdx & any( bsxfun(@eq, g, pairwise(k,:)) , 2 );
%# train
svmModel{k} = svmtrain(meas(idx,:), g(idx),'-s 0 -t 0');
%# test
predTest(:,k) = svmclassify(svmModel{k}, meas(testIdx,:));
end
pred = mode(predTest,2); %# voting: clasify as the class receiving most votes
%# performance
cmat = confusionmat(g(testIdx),pred);
acc = 100*sum(diag(cmat))./sum(cmat(:));
fprintf('SVM (1-against-1):\naccuracy = %.2f%%\n', acc);
fprintf('Confusion Matrix:\n'), disp(cmat)
错误:
Reference to non-existent field 'SupportVectors'.
Error in svmclassify (line 60)
if size(sample,2)~=size(svmStruct.SupportVectors,2)
Error in test_onevsone (line 21)
predTest(:,k) = svmclassify(svmModel{k}, meas(testIdx,:));
我也试试,svmModel{1}.SupportVectors。看起来 SupportVectors 不是按结构返回的。
请有人修复这个错误... 谢谢...
【问题讨论】:
标签: matlab classification svm libsvm