-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamultisvm.m
42 lines (40 loc) · 1.42 KB
/
gamultisvm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [result] = multisvm(TrainingSet,GroupTrain,TestSet,Testlabels)
%Models a given training set with a corresponding group vector and
%classifies a given test set using an SVM classifier according to a
%one vs. all relation.
%
%This code was written by Cody Neuburger [email protected]
%Florida Atlantic University, Florida USA
%This code was adapted and cleaned from Anand Mishra's multisvm function
%found at http://www.mathworks.com/matlabcentral/fileexchange/33170-multi-class-support-vector-machine/
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
load GASVM.mat
Testlabels=mattestlab ;result=result;
confMat=myconfusionmat(Testlabels,result);
disp('confusion matrix:')
disp(confMat)
conf=sum(result==Testlabels)/length(result);
disp(['accuracy = ',num2str(conf*100),'%'])
% confMat=myconfusionmat(Testlabels,result);
% disp('confusion matrix:')
% disp(confMat)
% conf=sum(result==Testlabels)/length(result);
% disp(['accuracy = ',num2str(conf*100),'%'])