-
Notifications
You must be signed in to change notification settings - Fork 0
/
decision_tree_classifier.m
53 lines (39 loc) · 1.81 KB
/
decision_tree_classifier.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
52
53
function decision = decision_tree_classifier(v, train_set, class_label, numerical)
fprintf('*** DECISION TREE CLASSIFIER ***\n');
% alpha is a vector that contains the alphabeth of the class (0, 1)
alpha = unique(class_label);
level = 0;
tree = [];
to_take = [1 2 3];
branches = [];
% matrix that contains all the branches generated by the tree, in terms of number of
% variable considered. For example [[1, 3, 2], [], ..] means that the brach is made
% by X1-->X3-->X2 ...
tree = [];
% vector that contains a single brach: as soon as a branch is completed,
% this variable is cleaned
labels = [];
% matrix that contains all the labels associated to the branches generated by the tree.
% For example if the branchs [[0, 1, 1], [], ...] means that the brach is made
% by X1 ==0 --> X3 == 1 --> X2 == 1
lab = [];
% vector that contains a single set of labels of the branch analized: when
% the branch is terminated this variable is setted empty
classification = [];
% vector that contains all the classification related to the branches and
% the label generated
thresholds=[];
% matrix that contains all the threshold associated to the branches generated by
% the tree, equal to the threshold choosen if the corrispondent variable is
% numerical or equal to inf if it is not.
thresh = [];
% vector that contains a single set of threshold of the branch analized: when
% the branch is terminated this variable is setted empty
[branches, labels, thresholds, classification] = build_tree(level, train_set, class_label, to_take, tree, lab, alpha, numerical, branches, labels,classification, thresholds, thresh);
tree = [];
s = size(v);
for i=1:s(1)
new = v(i,:);
decision = classifier(new, numerical, branches, labels, thresholds, classification);
fprintf('\nelement: [%d, %d, %d] \tclass: %d', new(1), new(2), new(3), decision);
end