-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomposition.py
137 lines (115 loc) · 3.76 KB
/
composition.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
import json
from sklearn import tree
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn import svm
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
class Composition(object):
def __init__(self):
with open('history.json') as data_file:
self.history = json.load(data_file)
X = []
y = []
i = 0
for game in self.history:
winner_composition = self.composition_classe_to_number(game.get('winner').get('composition'))
loser_composition = self.composition_classe_to_number(game.get('loser').get('composition'))
if i == 1:
i = 0
X.append([winner_composition, loser_composition])
y.append([1, len(game.get('winner').get('deaths'))])
else:
i = 1
X.append([loser_composition, winner_composition])
y.append([-1, - len(game.get('winner').get('deaths'))])
X_fit = X[+100:]
y_fit = y[+100:]
X_test = X[:+100]
y_test = y[:+100]
X_fit = np.array(X_fit)
y_fit = np.array(y_fit)
nsamples, nx, ny = X_fit.shape
X_fit = X_fit.reshape((nsamples, nx * ny))
X_test = np.array(X_test)
y_test = np.array(y_test)
nsamples, nx, ny = X_test.shape
X_test = X_test.reshape((nsamples, nx * ny))
model = RandomForestClassifier()
# Train the model using the training sets and check score
model.fit(X_fit, y_fit)
# #Equation coefficient and Intercept
predict = model.predict(X_test)
print(predict)
print(y_test)
win = 0
deathdiff = 0
i = 0
comparison = []
for prediction in predict:
result = y_test[i]
comparison.append([prediction[0] - result[0], prediction[1] - result[1]])
for comp in comparison:
if comp[0] == 0:
win += 1
deathdiff += abs(comp[1])
print(win)
print(deathdiff)
# #
# for prediction in predict - y_test:
# if i == 0:
# win = win + 1
# else:
# lose = lose + 1
# print("wins : ", win)
# print("loses : ", lose)
def composition_classe_to_number(self, composition):
number_composition = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for classe in composition:
number_composition[self.classe_to_number(classe)] = 1
return number_composition
def composition_number_to_classe(self, composition):
classe_composition = []
for number in composition:
classe_composition.append(self.number_to_classe(number))
return classe_composition
def classe_to_number(self, classe):
return {
'Osamodas': 0,
'Sacrieur': 1,
'Pandawa': 2,
'Eniripsa': 3,
'Eliotrope': 4,
'Enutrof': 5,
'Iop': 6,
'Sadida': 7,
'Sram': 8,
'Feca': 9,
'Ecaflip': 10,
'Zobal': 11,
'Cra': 12,
'Steamer': 13,
'Xelor': 14,
'Roublard': 15
}[classe]
def number_to_classe(self, number):
return {
0: 'Osamodas',
1: 'Sacrieur',
2: 'Pandawa',
3: 'Eniripsa',
4: 'Eliotrope',
5: 'Enutrof',
6: 'Iop',
7: 'Sadida',
8: 'Sram',
9: 'Feca',
10: 'Ecaflip',
11: 'Zobal',
12: 'Cra',
13: 'Steamer',
14: 'Xelor',
15: 'Roublard'
}[number]
composition = Composition()