-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoolTree.py
More file actions
65 lines (57 loc) · 2.06 KB
/
poolTree.py
File metadata and controls
65 lines (57 loc) · 2.06 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
from tree import makeNode
from node import Node
import numpy as np
class PoolTree:
def __init__(self, allData, classCount, catAmm, partitionStyle = True, entropyFunc = 0, attTypes = None, repetition = 0, entThresh=0.0):
self.time = None
dataArr = [[] for _ in range(classCount)]
for row in allData:
rowClass = row[-1] -1
rowFalse = row.copy()
rowFalse[-1] = 0
rowTrue = row.copy()
rowTrue[-1] = 1
for i in range(classCount):
if int(rowClass) == i:
dataArr[i].append(rowTrue)
else:
dataArr[i].append(rowFalse)
for i in range(len(dataArr)):
dataArr[i] = np.array(dataArr[i])
self.nodeArr = [makeNode(data, catAmm, partitionStyle=False, entropyFunc=0, catTypeArr=attTypes, repetition = repetition, entThresh = entThresh) for data in dataArr]
def __str__(self):
for node in self.nodeArr:
print(node)
return ""
def classify(self, row):
resArr = []
elseArr = []
for i, node in enumerate(self.nodeArr):
rowClass, percent = node.classifyPercent(row)
if rowClass == 1:
resArr.append((i, percent))
else:
elseArr.append((i, percent))
result = 1
#Clasificador con porcentajes
if resArr == []:
minRes = elseArr[0][0]
minResVal = elseArr[0][1]
for a in elseArr[1:]:
if a[1] < minResVal:
minResVal = a[1]
minRes = a[0]
result = minRes
elif len(resArr) > 1:
maxRes = resArr[0][0]
maxResVal = resArr[0][1]
for a in resArr[1:]:
if a[1] > maxResVal:
maxResVal = a[1]
maxRes = a[0]
result = maxRes
else:
result = resArr[0][0]
return result + 1
def setTime(self, time):
self.time = time