-
Notifications
You must be signed in to change notification settings - Fork 7
/
demo.py
28 lines (24 loc) · 859 Bytes
/
demo.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
import pyC45,csv
if __name__=="__main__":
#train a C45 decision tree and save the tree as an XML file
reader = csv.reader(file('./data/training_set.csv'))
training_obs=[]
training_cat=[]
for line in reader:
training_obs.append(line[:-1])
training_cat.append(line[-1])
pyC45.train(training_obs,training_cat,"DecisionTree.xml")
#test the C45 decision tree
reader = csv.reader(file('./data/training_set.csv'))
answer=[]
testing_obs=[]
for line in reader:
testing_obs.append(line[:-1])
answer.append(line[-1])
answer.pop(0)
prediction=pyC45.predict("DecisionTree.xml",testing_obs)
err=0
for i in range(len(answer)):
if not answer[i]==prediction[i]:
err=err+1
print "error rate=",round(float(err)/len(prediction)*100,2),"%"