0

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 are not return by structure.

Some one please fix this bug... Thank you...

Community
  • 1
  • 1
shivang patel
  • 297
  • 1
  • 5
  • 15

1 Answers1

0

Your error is in line 18, svmModel{k} = svmtrain(meas(idx,:), g(idx),'-s 0 -t 0');. svmtrain function accept 2 + 2n input. Correct syntax is: svmtrain(Training, Group) or svmtrain(Training, Group, Name, Value). Name and Value is pair argument. Name is the argument name and Value is the corresponding value. You use '-s 0 -t' as third and this is not matlab argument Name! Fix it and use your code.

Ahmad Sarabian
  • 144
  • 3
  • 13