-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCM_SVM.m
23 lines (21 loc) · 931 Bytes
/
CM_SVM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
classdef CM_SVM
properties
mapper
end
methods
function obj = CM_SVM(dataMapper)
obj.mapper = dataMapper;
end
function model = train(obj, dataSamples, dataLabels, x, y)
myMapper = obj.mapper;
dataLabels = arrayfun(@myMapper.ChangeLabelToInteger, dataLabels); % must be used otherwise throw away double labels
model = svmtrain(double(dataLabels), dataSamples, sprintf('-c %f -g %f -b 1 -q -t 0', x, y));
end
function [plabels,accuracy,prob_estimates] = test(obj, testSamples, testLabels, model)
myMapper = obj.mapper;
testLabels = arrayfun(@myMapper.ChangeLabelToInteger, testLabels);
[plabels,accuracy,prob_estimates] = svmpredict(double(testLabels), testSamples, model, '-b 1 -q');
plabels = arrayfun(@myMapper.ChangeIntegerToLabel, plabels);
end
end
end