[b4b313]: / classification / RUSboost / runSRB.m

Download this file

56 lines (37 with data), 1.4 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
function [rusTree, istrain, istest] = runSRB(X,Y)
%RUNSRB Summary of this function goes here
% Detailed explanation goes here
%% Transform data into a usable form
%Semantic labels
label = 'Sphericity';
%Show distribution for semantic label
fprintf('%s%s\n','Tabulation for: ', label);
tabulate(Y);
%create weak learner template for RUSBoosting to build an ensemble on
% TODO: CHANGE THESE PARAMS TO SOMETHING ELSE
t = ClassificationTree.template();
%% Build testing and training sets
%build training and testing sets
part = cvpartition(Y,'holdout',0.25);
istrain = training(part);
istest = test(part);
%% Run RUSBoosting
%build training sets
trainingX = X(istrain,:);
trainingY = Y(istrain);
%Run a decision tree
%tree = ClassificationTree.fit(trainingX,trainingY);
%run the RUSboost on a semantic label
rusTree = fitensemble(trainingX,trainingY,'RUSBoost',1000,'Tree',...
'LearnRate',1,'nprint',100);
%% Plot error rate
%build testing sets
testingX = X(istest,:);
testingY = Y(istest);
figure;
plot(loss(rusTree,testingX,testingY,'mode','cumulative'));
grid on;
xlabel('Number of trees');
ylabel('Test classification error');
disp('end');
end