-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.m
52 lines (49 loc) · 1.37 KB
/
test.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
43
44
45
46
47
48
49
50
51
clear;
clc;
err_dataset = load('err_dataset');
err_train = cell2mat(err_dataset.err_events_train);
err_train_label = err_dataset.events_flag_train;
err_test = cell2mat(err_dataset.err_events_test);
err_test_label = err_dataset.events_flag_test;
tpr_cell = {};
fpr_cell = {};
index = 0;
legends = [];
levels = 0.1:0.1:1;
c_params = 0.1:0.1:20;
for level = levels
tpr_array = [];
fpr_array = [];
fprintf('level:%d\n',level);
for c = c_params
fprintf('c:%d\n',c);
svm_struct = svmtrain(err_train,err_train_label,'KKTViolationLevel',level,'boxconstraint',c, 'kernel_function','rbf');
extimate = svmclassify(svm_struct,err_test);
% subplot(211)
% bar(extimate);
% subplot(212)
% bar(err_test_label);
conf = confusionmat(err_test_label,extimate);
tp = conf(2,2);
tn = conf(1,1);
fn = conf(2,1);
fp = conf(1,2);
tpr = tp / (tp + fn);
fpr = fp / (fp + tn);
tpr_array = [tpr_array tpr];
fpr_array = [fpr_array fpr];
end
index = index + 1;
tpr_cell{index} = tpr_array;
fpr_cell{index} = fpr_array;
legends{index} = num2str(level);
end
save('c_parame.mat','levels','c_params','tpr_cell','fpr_cell','legends');
% figure
%
% for i = 1:length(fpr_cell)
% plot(fpr_cell{i},tpr_cell{i},'-o');
% hold on;
% end
% legend(legends);
% hold off;