Multiclass Svm supports 2 methods: 1vs1 and 1vsall. I've finished my code with 1 vs all aspect but i wanna compare it and check if 1 vs 1 will yield better classification results:
%% SVM Multiclass Example
% SVM is inherently one vs one classification.
% This is an example of how to implement multiclassification using the
% one vs all approach.
TrainingSet=[ 1 10;2 20;3 30;4 40;5 50;6 66;3 30;4.1 42];
TestSet=[3 34; 1 14; 2.2 25; 6.2 63];
GroupTrain=[1 1 2 2 3 3 2 2];
results = multisvm(TrainingSet, GroupTrain, TestSet);
disp('multi class problem');
disp(results);
The code for the function multisvm
:
u=unique(GroupTrain);
numClasses=length(u);
result = zeros(length(TestSet(:,1)),1);
%build models
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(GroupTrain==u(k));
models(k) = svmtrain(TrainingSet,G1vAll);
end
%classify test cases
for j=1:size(TestSet,1)
for k=1:numClasses
if(svmclassify(models(k),TestSet(j,:)))
break;
end
end
result(j) = k;
end
Aucun commentaire:
Enregistrer un commentaire