-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (27 loc) · 772 Bytes
/
app.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
from tree import *
def print_tree(node):
if node.is_leaf():
print "classe: " + str(node.value)
else:
print "node with attribute: " + str(node.value)
for direction, child in node.childs.items():
print "going to direction: " + str(direction)
print_tree(child)
tree = Tree()
tree.load_data_frame("data/input_data3.csv")
tree.set_target("buys_computer")
categoricals = ["age", "income", "student", "credit_rating"]
numerics = []
tree.set_categorical_attributes(categoricals)
tree.set_numerical_attributes(numerics)
raiz = tree.build_tree()
print_tree(raiz)
print
print
inst = {
"age": "youth",
"income": "high",
"student": "no",
"credit_rating": "fair"
}
print tree.classify_instance(inst, raiz)