-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsvm_classifyHighLevel.m
More file actions
78 lines (43 loc) · 1.81 KB
/
svm_classifyHighLevel.m
File metadata and controls
78 lines (43 loc) · 1.81 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function predicted=svm_classifyHighLevel(percentage_training,feature)
load SubSetNormalizedFeaturesSet2.mat
y=SubSetNormalizedFeaturesSet2;
clear SubSetNormalizedFeaturesSet2;
% load NormalizedFeaturesSet2.mat
% y=NormalizedFeaturesSet2;
% clear NormalizedFeaturesSet2;
num_features=size(y,2)-1
[class1, class2 ,class3]=prepareData(y);
percentage_testing=30;
[train_samples_class1 test_samples_class1]=selectSamples(class1,percentage_training,percentage_testing);
percentage_testing=30;
[train_samples_class2 test_samples_class2]=selectSamples(class2,percentage_training,percentage_testing);
percentage_testing=30;
[train_samples_class3 test_samples_class3]=selectSamples(class3,percentage_training,percentage_testing);
% Note that feature 1 is in the columns,feature num_features is in the columns
%%
X= [train_samples_class1 ;train_samples_class2];
% Y=[ones(2000,1) ;2*ones(2000,1);3*ones(2000,1)];
Y=[ones(length(train_samples_class1),1);2*ones(length(train_samples_class2),1)];
inputs=(X);
targets=transpose(Y);
SVMstruct12 = svmtrain(inputs,targets,'Kernel_Function','rbf');
%%
X= [train_samples_class1 ;train_samples_class3];
% Y=[ones(2000,1) ;2*ones(2000,1);3*ones(2000,1)];
Y=[ones(length(train_samples_class1),1);3*ones(length(train_samples_class3),1)];
inputs=(X);
targets=transpose(Y);
SVMstruct13 = svmtrain(inputs,targets,'Kernel_Function','rbf');
%%
X= [train_samples_class2 ;train_samples_class3];
% Y=[ones(2000,1) ;2*ones(2000,1);3*ones(2000,1)];
Y=[2*ones(length(train_samples_class2),1);3*ones(length(train_samples_class3),1)];
inputs=(X);
targets=transpose(Y);
SVMstruct23 = svmtrain(inputs,targets,'Kernel_Function','rbf');
%%
p12=svmclassify(SVMstruct12,feature);
p13=svmclassify(SVMstruct13,feature);
p23=svmclassify(SVMstruct23,feature);
predicted = combineBinaryDecisons(p12,p23,p13)
end