-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_hoeffding_tree.py
57 lines (51 loc) · 1.68 KB
/
test_hoeffding_tree.py
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
import unittest
import math
from hoeffding_tree import HoeffdingTree
class TestHoeffdingTree(unittest.TestCase):
def test1(self):
Nmin = 2
delta = 0.2
R = 1
logfunc = math.log2
tree = HoeffdingTree(Nmin, delta, R, logfunc)
data_columns = {
'time': ['1-2', '2-7', '>7', '1-2', '>7', '1-2', '2-7', '2-7'],
'gender': ['m', 'm', 'f', 'f', 'm', 'm', 'f', 'm'],
'area': ['urban', 'rural', 'rural', 'rural', 'rural', 'rural', 'urban', 'urban']
}
label_columns = [
['low', 'high', 'low', 'high', 'high', 'high', 'low', 'low']
]
tree.fit(data_columns, label_columns[0])
def test2(self):
Nmin = 2
delta = 0.2
R = 1
logfunc = math.log2
tree = HoeffdingTree(Nmin, delta, R, logfunc)
data_columns = {
'ab': ['a', 'b', 'b', 'b', 'a', 'a', 'b', 'b'],
'012': [2, 1, 0, 1, 1, 0, 1, 2],
'm1m2': ['m1', 'm2', 'm1', 'm2', 'm2', 'm1', 'm2', 'm1']
}
label_columns = [
[0, 0, 1, 1, 0, 0, 1, 1]
]
tree.fit(data_columns, label_columns[0])
def test3(self):
Nmin = 2
delta = 0.2
R = 1
logfunc = math.log2
tree = HoeffdingTree(Nmin, delta, R, logfunc)
data_columns = {
'ab': ['a', 'b', 'b', 'b', 'a', 'a', 'b', 'b'],
'012': [2, 1, 0, 1, 1, 2, 1, 0],
'm1m2': ['m1', 'm2', 'm1', 'm2', 'm2', 'm1', 'm2', 'm1']
}
label_columns = [
[0, 0, 1, 1, 0, 0, 1, 1]
]
tree.fit(data_columns, label_columns[0])
if __name__ == '__main__':
unittest.main()