-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpredict.py
76 lines (61 loc) · 2.36 KB
/
predict.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
import math
import numpy as np
import pandas as pd
from scipy import stats
from mvp_model import zscore_model, stats_of_interest
global num_players
field_zscores = [] #each object inside is a list of the zscores for each particular stat (by Stat)
players = [] #each object inside is a list of a player's zscores for each stat of interest (by Player)
MVP_MODEL = zscore_model() #list of MVP's zscores for each stat of interest
FILE_PATH = input('Choose a season (2014, 2016, 2017, 2018, 2019, 2020): ')
if FILE_PATH == '2020':
FILE_PATH = 'mvpForecast'
else:
FILE_PATH = 'mvp'+FILE_PATH
field_df = pd.read_csv('data/' + FILE_PATH + '.csv')
def eucliddist(a,b):
sum = 0.0
for i in range(len(a)):
sum += (a[i]-b[i])**2
return math.sqrt(sum)
def produceZs():
global num_players
num_players = len(field_df.index)
for stat in stats_of_interest:
stat_for_t20 = field_df[stat].tolist()
math_ready = np.array(stat_for_t20)
one_stat_zscores = np.array(stats.zscore(math_ready))
field_zscores.append(one_stat_zscores)
# print()
# print(stat)
# print(one_stat_zscores)
def compilePlayerZ():
for i in range(num_players):
player_stats = []
for zscores in field_zscores:
player_stats.append(zscores[i])
players.append(player_stats)
def findAvgScore():
avgScores = list(map(lambda player: [field_df.iloc[players.index(player)][field_df.columns.get_loc('Player')], np.mean(player)], players))
return sorted(avgScores, key=lambda generated_metric: generated_metric[1], reverse=True)
def findScoreTrend():
distances = list(map(lambda player: [field_df.iloc[players.index(player)][field_df.columns.get_loc('Player')], eucliddist(player, MVP_MODEL)], players))
return sorted(distances, key=lambda generated_metric: generated_metric[1])
def getName(index):
return field_df.iloc[index][field_df.columns.get_loc('Player')]
#test
print("mvp z-score model compared to top 20 PER players")
print(stats_of_interest)
print(MVP_MODEL)
print()
produceZs()
compilePlayerZ()
# ranking = findScoreTrend()
# print("Trend Ranking:")
# for rank in ranking:
# print('{} {}: {}'.format(ranking.index(rank)+1, rank[0], rank[1]))
print()
print("Algorithm Ranking:")
ranking = findAvgScore()
for rank in ranking:
print('{} {}: {}'.format(ranking.index(rank)+1, rank[0], rank[1]))