File size: 4,012 Bytes
7e8b063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "gbg_and_odds_this_year = pd.read_csv('Source/Data/gbg_and_odds_this_year.csv')\n",
    "results = pd.read_csv('Source/Data/results.csv')\n",
    "\n",
    "from Source.Predict.predict import predict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle as pkl\n",
    "with open('Source/Pickles/team_abbreviation_to_name.pkl', 'rb') as f:\n",
    "    team_abbreviation_to_name = pkl.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 32/32 [00:04<00:00,  6.79it/s]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "predictions = {}\n",
    "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):\n",
    "    if week!=1:\n",
    "        predictions[game_id] = predict(home,away,season,week,total)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'winners_correct': '5', 'winners_incorrect': '11', 'over_unders_correct': '7', 'over_unders_incorrect': '9'}\n"
     ]
    }
   ],
   "source": [
    "predictions_df = pd.DataFrame(predictions).T\n",
    "predictions_df['predicted_winner'] = [i['Winner'][0] if type(i['Winner'])==list else None for i in predictions_df[1]]\n",
    "predictions_df['predicted_winner'] = predictions_df['predicted_winner'].map(team_abbreviation_to_name)\n",
    "predictions_df['predicted_over_under'] = [i['Over/Under'][0] if type(i['Over/Under'])==list else None for i in predictions_df[2]]\n",
    "predictions_df = predictions_df.merge(results, left_index=True, right_on='game_id').merge(gbg_and_odds_this_year[['game_id','Total Score Close']]).dropna(subset=['predicted_winner'])\n",
    "predictions_df['over_under'] = ['Over' if t>tsc else 'Under' if t<tsc else 'Push' for t,tsc in predictions_df[['total','Total Score Close']].values]\n",
    "\n",
    "predictions_df['winner_correct'] = (predictions_df['predicted_winner']==predictions_df['winner']).astype(int)\n",
    "predictions_df['winner_incorrect'] = (predictions_df['predicted_winner']!=predictions_df['winner']).astype(int)\n",
    "\n",
    "predictions_df['over_under_correct'] = (predictions_df['predicted_over_under']==predictions_df['over_under']).astype(int)\n",
    "predictions_df['over_under_incorrect'] = (predictions_df['predicted_over_under']!=predictions_df['over_under']).astype(int)\n",
    "\n",
    "winners_correct = predictions_df['winner_correct'].sum()\n",
    "winners_incorrect = predictions_df['winner_incorrect'].sum()\n",
    "\n",
    "over_unders_correct = predictions_df['over_under_correct'].sum()\n",
    "over_unders_incorrect = predictions_df['over_under_incorrect'].sum()\n",
    "\n",
    "record = {\"winners_correct\":str(winners_correct),\n",
    "        \"winners_incorrect\":str(winners_incorrect),\n",
    "        \"over_unders_correct\":str(over_unders_correct),\n",
    "        \"over_unders_incorrect\":str(over_unders_incorrect)}\n",
    "\n",
    "import json\n",
    "with open('Static/record.json', 'w') as f:\n",
    "    json.dump(record,f)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}