-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnropyTree.py
More file actions
114 lines (90 loc) · 2.55 KB
/
Copy pathEnropyTree.py
File metadata and controls
114 lines (90 loc) · 2.55 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'''
Areen Abu Caf 212654719
Fadi Amon 212472542
Rasheed Abu Mdeagm 212555650
'''
class EntropyTree:
'''
tree contain data frame and the split point to split the data to right and left.
entropy of the data and left right nodes.
'''
def __init__(self, data, left=None, right=None, split=None,entropy=None):
'''
:param data: pandas data frame
:param left: left node
:param right: right node
:param split: the split point
:param entropy: the entropy of the data
'''
self.data = data
self.split = split
self.entropy=entropy
self.right = right
self.left = left
def getRoot(self):
'''
:return: the root of the tree
'''
return self.data
def getSplit(self):
'''
:return: data split point
'''
return self.split
def getLeft(self):
'''
:return: left node
'''
return self.left
def getRight(self):
'''
:return: right node
'''
return self.right
def getLeafs(self):
'''
:return: all leaves
'''
if self.isLeaf():
return [self]
return self.left.getLeafs() + self.right.getLeafs()
def getNodes(self):
'''
:return: all the nodes without leaves
'''
if self.right.isLeaf() and self.left.isLeaf():
return [self]
return self.left.getNodes() + [self] + self.right.getNodes()
def getLevel_h(self):
'''
:return: Return the nodes in level h-1
'''
if self.right.isLeaf() and self.left.isLeaf():
return [self]
return self.left.getLevel_h() + self.right.getLevel_h()
def setLeft(self, node):
'''
:param node: EntropyTree object to set it on left node
'''
self.left = node
def setRight(self, node):
'''
:param node: EntropyTree object to set it on right node
'''
self.right = node
def setSplit(self, split):
'''
:param split: Split point of the data
'''
self.split = split
def setEntropy(self,Entropy):
'''
:param Entropy: Entropy of the data
:return:
'''
self.entropy=Entropy
def isLeaf(self):
'''
:return: True if the node is leaf
'''
return self.left is None and self.right is None