forked from kyleskom/NBA-Machine-Learning-Sports-Betting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (62 loc) · 3.27 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
import argparse
import pandas as pd
import tensorflow as tf
from src.Predict import NN_Runner, XGBoost_Runner
from src.Utils.Dictionaries import team_index_current
from src.Utils.tools import get_json_data, to_data_frame, get_todays_games_json, create_todays_games
todays_games_url = 'https://data.nba.com/data/10s/v2015/json/mobile_teams/nba/2020/scores/00_todays_scores.json'
data_url = 'https://stats.nba.com/stats/leaguedashteamstats?' \
'Conference=&DateFrom=&DateTo=&Division=&GameScope=&' \
'GameSegment=&LastNGames=0&LeagueID=00&Location=&' \
'MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&' \
'PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&' \
'PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&' \
'Season=2020-21&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&' \
'StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision='
def createTodaysGames(games, df):
match_data = []
todays_games_uo = []
for game in games:
home_team = game[0]
away_team = game[1]
todays_games_uo.append(input(home_team + ' vs ' + away_team + ': '))
home_team_series = df.iloc[team_index_current.get(home_team)]
away_team_series = df.iloc[team_index_current.get(away_team)]
stats = home_team_series.append(away_team_series)
match_data.append(stats)
games_data_frame = pd.concat(match_data, ignore_index=True, axis=1)
games_data_frame = games_data_frame.T
frame_ml = games_data_frame.drop(columns=['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME'])
data = frame_ml.values
data = data.astype(float)
return data, todays_games_uo, frame_ml
def main():
data = get_todays_games_json(todays_games_url)
games = create_todays_games(data)
data = get_json_data(data_url)
df = to_data_frame(data)
data, todays_games_uo, frame_ml = createTodaysGames(games, df)
if args.nn:
print("------------Neural Network Model Predictions-----------")
data = tf.keras.utils.normalize(data, axis=1)
NN_Runner.nn_runner(data, todays_games_uo, frame_ml, games)
print("-------------------------------------------------------")
if args.xgb:
print("---------------XGBoost Model Predictions---------------")
XGBoost_Runner.xgb_runner(data, todays_games_uo, frame_ml, games)
print("-------------------------------------------------------")
if args.A:
print("---------------XGBoost Model Predictions---------------")
XGBoost_Runner.xgb_runner(data, todays_games_uo, frame_ml, games)
print("-------------------------------------------------------")
data = tf.keras.utils.normalize(data, axis=1)
print("------------Neural Network Model Predictions-----------")
NN_Runner.nn_runner(data, todays_games_uo, frame_ml, games)
print("-------------------------------------------------------")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Model to Run')
parser.add_argument('-xgb', action='store_true', help='Run with XGBoost Model')
parser.add_argument('-nn', action='store_true', help='Run with Neural Network Model')
parser.add_argument('-A', action='store_true', help='Run all Models')
args = parser.parse_args()
main()