-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_id3.py
executable file
·39 lines (28 loc) · 945 Bytes
/
test_id3.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
#!/usr/bin/env python
#
# filename: test_id3_v2.py
# authors: Jon David and Jarrett Decker
# date: Thursday, February 10, 2016
#
import pdb
from datadef import ShroomDefs
from database import ShroomDatabase
from id3_v2 import *
deffilename = "_shroom.data.definition"
trainfilename = "./data/training.dat"
testfilename = "./data/testing.dat"
print("\n\n==== Test id3_v2 ====")
print("definition file: ", deffilename)
print("training set: ", trainfilename)
mydefs = ShroomDefs(deffilename)
mydb = ShroomDatabase([], trainfilename)
#pdb.set_trace()
gain_criteria = InformationGainCriteria()
tree = id3(gain_criteria, mydb, 'class', mydefs.attr_set, mydefs)
tree.print_entire_tree()
print("\n\n==== Test classification====")
testdb = ShroomDatabase([], testfilename)
record = testdb.records[0]
classification = tree.classify(record)
print("record to classify: " + record.get_raw_string())
print("classification: " + classification)