one vs one svm multiclass classification matlab code
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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..
0 comentarios
Respuestas (1)
vianney p
el 6 de Jun. de 2016
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.
0 comentarios
Ver también
Categorías
Más información sobre Classification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!