-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_classifier.py
153 lines (140 loc) · 2.63 KB
/
tree_classifier.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
inputs = [
'hotkey01',
'hotkey82',
'hotkey30',
's',
'hotkey21',
'hotkey00',
'hotkey60',
'hotkey41',
'hotkey80',
'hotkey90',
'sMineral',
'hotkey10',
'hotkey91',
'hotkey71',
'hotkey81',
'hotkey40',
'hotkey31',
'hotkey12',
'sBase',
'hotkey62',
'hotkey42',
'hotkey11',
'hotkey02',
'hotkey50',
'hotkey61',
'hotkey70',
'hotkey22',
'hotkey52',
'hotkey20',
'hotkey72',
'hotkey32',
'hotkey92',
'hotkey51'
]
players = [
'/YongHwa/',
'/ParalyzE/',
'/INnoVation/',
'/LiquidTLO/',
'/PartinG/',
'/Lilbow/',
'/sOs/',
'/WhiteRa/',
'/Super/',
'/Symbol/',
'/ByuL/',
'/iGJim/',
'/Stardust/',
'/FanTaSy/',
'/Soulkey/',
'Life/',
'/Leenock/',
'/Kane/',
'/Stats/',
'/soO/',
'/DRG/',
'/MaNa/',
'/Rain/',
'/Bbyong/',
'/Rogue/',
'/Dream/',
'/yoeFWSan/',
'/Zest/',
'/viOLet/',
'/Hydra/',
'/TYTY/',
'/MǂForGG/',
'/Classic/',
'/Bunny/',
'/Life/',
'/CMStormPolt/',
'/ForGG/',
'/Sen/',
'/LiquidSnute/',
'/Polt/',
'/Pigbaby/',
'/True/',
'/Curious/',
'/VortiX/',
'/YoDa/',
'/HuK/',
'/Welmu/',
'/Nerchio/',
'/hydra/',
'/Happy/',
'/Dear/',
'/LiquidBunny/',
'/MyuNgSiK/',
'/FireCake/',
'/JJAKJI/',
'/Cure/',
'/Maru/',
'/AxHeart/',
'/Solar/',
'/iaguz/',
'/Trap/',
'/herO/',
'/MMA/',
'/Golden/',
'/Stork/',
'/MinChul/',
'/ShoWTimE/',
'/LiquidTaeJa/',
'/Dark/',
'/Bomber/',
'/iGXiGua/',
'/HyuN/'
]
races = ['Terran', 'Protoss', 'Zerg']
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
import numpy as np
train_size = 4099
test_size = 1025
le = LabelEncoder()
le.fit(races)
X = []
y = []
for line in open('train.csv', 'r'):
train = line.split(',')
[player, race] = train[0].split(';')
if race == 'Terran\n':
race = 'Terran'
feature = [0 for i in range(len(inputs))]
for i in range(1, len(train), 2):
feature[inputs.index(train[i])] += 1
normalize_term = sum(feature)
if normalize_term != 0:
feature = [x/normalize_term for x in feature]
feature.append(le.transform([race])[0])
X.append(feature)
y.append(train[0])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
dtc = DecisionTreeClassifier()
dtc.fit(X_train, y_train)
print(dtc.score(X_test, y_test))
#print(X_train[0])
#print(Y_train[0])