-
Notifications
You must be signed in to change notification settings - Fork 0
/
Classify.py
43 lines (32 loc) · 910 Bytes
/
Classify.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
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 9 13:18:55 2018
@author: morten
"""
import numpy as np
from initData import *
classNames = ['Poor', 'Lower', 'Middle', 'Upper']
attributeNames = [
'hours',
'iq',
'educ',
'exper',
'tenure',
'age',
'black'
]
classIndices = np.asarray(np.mat(np.empty((N))).T).squeeze()
for i in range(0,N):
if y[i] <= np.percentile(y,25):
classIndices[i] = 0
elif y[i] <= np.percentile(y,50):
classIndices[i] = 1
elif y[i] <= np.percentile(y,75):
classIndices[i] = 2
else:
classIndices[i] = 3
C = len(classNames)
dtcGini = tree.DecisionTreeClassifier(criterion='gini', min_samples_split=2)
dtcGini = dtcGini.fit(classX,classIndices)
out = tree.export_graphviz(dtcGini, out_file='2sampleGini.gvz', feature_names=attributeNames)
graphviz.render('dot','png','2sampleGini.gvz')