필터 지우기
필터 지우기

one vs one svm multiclass classification matlab code

조회 수: 12 (최근 30일)
Shivang Patel
Shivang Patel 2015년 12월 9일
답변: vianney p 2016년 6월 6일
Here is my code for one-vs-one. This code not written by @amro. I can't understand why this happening. Everything looks very simple when I studied code. Please help me to fix it. I am using matlab2014a.
Code : One vs One
%# 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)
Error:
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,:));
I also try,
svmModel{1}.SupportVectors
And it's looks like SupportVectors is not available in structure.
Some one please fix this bug... Thank you..

답변 (1개)

vianney p
vianney p 2016년 6월 6일
the error is in this line svmModel{k} = svmtrain(meas(idx,:), g(idx),'-s 0 -t 0');
you need to verify the parameters for the function svmtrain. If you use svmModel{k} = svmtrain(meas(idx,:), g(idx)) it works.

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by