forked from 20020001-UET/dsa-decision-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStump.cpp
97 lines (81 loc) · 2.11 KB
/
Stump.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* This file is part of dsa-decision-tree
*
* Developed for the DSA UET course.
* This project was developed by Ba Luong and Gia Linh.
*/
#include "Stump.h"
Stump::Stump(int atr, int value, SplitData::SPLIT_VAL met, double _significance) : attribute(atr), compareValue(value), method(met), significance(_significance) { this->left = this->right = NULL; }
bool Stump::compare(Data *data)
{
switch (method)
{
case SplitData::ATTRIBUTE:
return SplitData::Attribute::compare(data, attribute, compareValue);
case SplitData::COMPARISON:
return SplitData::Comparison::compare(data, attribute, compareValue);
case SplitData::COMBINATION:
return SplitData::Combination::compare(data, attribute, compareValue);
default:
cout << "[EXCEPTION] Unknown method" << endl;
return true;
}
}
bool Stump::isTerminal()
{
return false;
}
char Stump::getLabel()
{
return ' ';
}
string Stump::toString()
{
stringstream ss;
ss << "Stump: " << attribute << " " << compareValue << " "
<< method << " " << significance << " " << left->getLabel()
<< " " << right->getLabel();
return ss.str();
}
char Stump::predict(vector<int> attribute)
{
switch (method)
{
case SplitData::ATTRIBUTE:
if (attribute.at(this->attribute) == compareValue)
return this->left->getLabel();
else
return this->right->getLabel();
;
break;
case SplitData::COMPARISON:
if (attribute.at(this->attribute) < compareValue)
{
return this->left->getLabel();
}
else
{
return this->right->getLabel();
}
break;
case SplitData::COMBINATION:
if (getBit(compareValue, attribute.at(this->attribute) - 1))
return this->left->getLabel();
else
return this->right->getLabel();
default:
cout << "default" << endl;
break;
}
}
double Stump::getSignificance()
{
return significance;
}
void Stump::setCode(int _code)
{
code = _code;
}
string Stump::getExport() {
return "";
}