-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.py
executable file
·84 lines (72 loc) · 2.56 KB
/
Main.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from gplearn.genetic import SymbolicRegressor
from Auth import get_auth
from Enums import Status
from Enums import Position
from models import Score
from clients import get_athletes, get_teams
def main():
escalation = {
Position.GOALKEEPER: 1,
Position.DEFENDER: 2,
Position.SIDE: 2,
Position.MIDFIELD: 4,
Position.ATTACKER: 2,
Position.COACH: 1
}
print("Getting auth")
auth = get_auth()
print("Getting teams")
teams = get_teams()
print("Getting athletes")
athletes = get_athletes(teams)
print("Getting scores")
scores = [athlete.get_row(auth) for athlete in athletes]
max_length = 0
for score in scores:
if len(score) > max_length:
max_length = len(score)
fixed_score = []
for score in scores:
fixed_score.append([0.0] * (max_length - len(score)) + score)
generations = 2000
print("Training using " + str(generations) + " generations. It can take a long time to end")
est_gp = SymbolicRegressor(
population_size=5000,
generations=generations,
stopping_criteria=0.01,
p_crossover=0.7,
p_subtree_mutation=0.1,
p_hoist_mutation=0.05,
p_point_mutation=0.1,
max_samples=0.9,
verbose=1,
parsimony_coefficient=0.01,
random_state=0,
const_range=(-50., 50.),
function_set=(
'add', 'sub', 'mul', 'div', 'sqrt', 'log', 'abs', 'neg', 'inv', 'max', 'min', 'sin', 'cos', 'tan'))
est_gp.fit([x[:-1] for x in fixed_score], [x[-1] for x in fixed_score])
predictions = est_gp.predict([x[:-1] for x in fixed_score])
print("Getting results")
results = [[athlete, prediction] for athlete, prediction in zip(athletes, predictions)]
results.sort(key=lambda x: -x[1])
print("\"Scale\",\"Name\",\"Team\",\"Position\",\"Status\",\"Price\",\"Prediction\"")
for result in results:
athlete = result[0]
prediction = result[1]
scale = athlete.status == Status.Probable and escalation[athlete.position] > 0
if scale:
escalation[athlete.position] = escalation[athlete.position] - 1
print("\"" +
("*" if scale else " ") + "\",\"" +
athlete.nick + "\",\"" +
athlete.club.name + "\",\"" +
str(athlete.position.name) + "\",\"" +
str(athlete.status.name) + "\"," +
str(athlete.price) + "," +
str(prediction))
print("Done")
if __name__ == "__main__":
main()