This repository was archived by the owner on Aug 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_model.py
80 lines (65 loc) · 1.96 KB
/
create_model.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
import pandas as pd
from collections import defaultdict
dataset = pd.read_csv('data/raw/dataset.csv', parse_dates=["Date"])
dataset.columns = ["Date", "Map", "Team1", "Team1Pts", "Team2", "Team2Pts"]
dataset["Team1LastWin"] = 0
dataset["Team2LastWin"] = 0
dataset["TeamHigher"] = 0
dataset["Team1WonLast"] = 0
dataset["Result"] = 0
ranking = {
'EnVyUs': 20,
'Virtus.pro': 29,
'TSM': 18,
'fnatic': 17,
'Natus Vincere': 16,
'NiP': 15,
'G2': 14,
'mousesports': 13,
'Luminosity': 12,
'Titan': 11,
'Cloud9': 10,
'dignitas': 9,
'CLG': 8,
'Liquid': 7,
'FlipSid3': 6,
'E-frag.net': 5,
'Conquest': 4,
'Renegades': 3,
'Vexed': 2,
'CSGL': 1,
}
won_last = defaultdict(int)
last_match_winner = defaultdict(int)
for index, row in dataset.sort_values("Date").iterrows():
team1 = row["Team1"]
team2 = row["Team2"]
team1_rank = 0;
team2_rank = 0;
if ranking.has_key(team1):
team1_rank = ranking[team1]
if ranking.has_key(team2):
team2_rank = ranking[team2]
team_higher = 0
if team1_rank > 0 and team1_rank > team2_rank:
team_higher = 1
elif team2_rank > 0 and not team1_rank > team2_rank:
team_higher = 2
teams = tuple(sorted([team1, team2]))
result = 0
if row["Team1Pts"] > row["Team2Pts"]:
result = 1
elif row["Team2Pts"] > row["Team1Pts"]:
result = 2
row["Team1LastWin"] = int(won_last[team1])
row["Team2LastWin"] = int(won_last[team2])
row["TeamHigher"] = int(team_higher)
row["Result"] = result
row["Team1WonLast"] = 1 if last_match_winner[teams] == row["Team1"] else 0
dataset.ix[index] = row
won_last[team1] = row["Result"] == 1
won_last[team2] = row["Result"] == 2
winner = row["Team1"] if row["Result"] == 1 else row["Team2"]
last_match_winner[teams] = winner
X_teams_expanded = dataset[["Result", "Date", "Team1", "Team2", "Map", "Team1LastWin", "Team2LastWin", "TeamHigher", "Team1WonLast"]].values
dataset.to_csv("data/samples.csv")