from datetime import datetime import numpy as np import pandas as pd pd.set_option('chained_assignment',None) pd.set_option('display.max_columns',None) import os import pickle as pkl from Source.Predict.predict import predict # get team abbreviations with open('Source/Pickles/team_abbreviation_to_name.pkl', 'rb') as f: team_abbreviation_to_name = pkl.load(f) # get this year's odds and results gbg_and_odds_this_year = pd.read_csv('Source/Data/gbg_and_odds_this_year.csv') results = pd.read_csv('Source/Data/results.csv') # make predictions from tqdm import tqdm print("Predicting games and getting record") predictions = {} for game_id,home,away,season,week,total in tqdm(gbg_and_odds_this_year[['game_id','home_team','away_team','Season','GP','Total Score Close']].values): if week!=1: predictions[game_id] = predict(home,away,season,week,total) # get record and save it predictions_df = pd.DataFrame(predictions).T predictions_df['predicted_winner'] = [i['Winner'][0] if type(i['Winner'])==list else None for i in predictions_df[1]] predictions_df['predicted_winner'] = predictions_df['predicted_winner'].map(team_abbreviation_to_name) predictions_df['predicted_over_under'] = [i['Over/Under'][0] if type(i['Over/Under'])==list else None for i in predictions_df[2]] predictions_df = predictions_df.merge(results, left_index=True, right_on='game_id').merge(gbg_and_odds_this_year[['game_id','Total Score Close','home_team','away_team','game_date']]).dropna(subset=['predicted_winner']) predictions_df['over_under'] = ['Over' if t>tsc else 'Under' if t