Spaces:
Runtime error
Runtime error
Commit
·
632a626
1
Parent(s):
5f81d51
Improve speed and add week selector
Browse files
Source/Predict/__pycache__/predict.cpython-311.pyc
CHANGED
Binary files a/Source/Predict/__pycache__/predict.cpython-311.pyc and b/Source/Predict/__pycache__/predict.cpython-311.pyc differ
|
|
Source/Predict/predict.py
CHANGED
@@ -7,6 +7,7 @@ import requests
|
|
7 |
from bs4 import BeautifulSoup
|
8 |
import warnings
|
9 |
warnings.filterwarnings("ignore")
|
|
|
10 |
|
11 |
# set dirs for other files
|
12 |
current_directory = os.path.dirname(os.path.abspath(__file__))
|
@@ -30,6 +31,20 @@ file_path = os.path.join(pickle_directory, 'team_abbreviation_to_name.pkl')
|
|
30 |
with open(file_path, 'rb') as f:
|
31 |
team_abbreviation_to_name = pkl.load(f)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def get_week():
|
34 |
headers = {
|
35 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
@@ -47,7 +62,6 @@ def get_week():
|
|
47 |
h2_tags = soup.find_all('h2')
|
48 |
year = h2_tags[0].getText().split(' ')[0]
|
49 |
week = h2_tags[0].getText().split(' ')[-1]
|
50 |
-
print(week)
|
51 |
return int(week), int(year)
|
52 |
|
53 |
|
@@ -104,12 +118,7 @@ def predict(home,away,season,week,total):
|
|
104 |
|
105 |
# create game id
|
106 |
game_id = str(season) + '_0' + str(week) + '_' + away_abbrev + '_' + home_abbrev
|
107 |
-
|
108 |
-
# moneyline
|
109 |
-
model = 'xgboost_ML_no_odds_71.4%'
|
110 |
-
file_path = os.path.join(model_directory, f'{model}.json')
|
111 |
-
xgb_ml = xgb.Booster()
|
112 |
-
xgb_ml.load_model(file_path)
|
113 |
|
114 |
try:
|
115 |
moneyline_result = results.loc[results['game_id']==game_id, 'winner'].item()
|
@@ -126,12 +135,6 @@ def predict(home,away,season,week,total):
|
|
126 |
moneyline = {'Winner': 'NA',
|
127 |
'Probabilities':['N/A'],
|
128 |
'Result': moneyline_result}
|
129 |
-
|
130 |
-
# over/under
|
131 |
-
model = 'xgboost_OU_no_odds_59.8%'
|
132 |
-
file_path = os.path.join(model_directory, f'{model}.json')
|
133 |
-
xgb_ou = xgb.Booster()
|
134 |
-
xgb_ou.load_model(file_path)
|
135 |
|
136 |
try:
|
137 |
result = results.loc[results['game_id']==game_id, 'total'].item()
|
|
|
7 |
from bs4 import BeautifulSoup
|
8 |
import warnings
|
9 |
warnings.filterwarnings("ignore")
|
10 |
+
from datetime import datetime
|
11 |
|
12 |
# set dirs for other files
|
13 |
current_directory = os.path.dirname(os.path.abspath(__file__))
|
|
|
31 |
with open(file_path, 'rb') as f:
|
32 |
team_abbreviation_to_name = pkl.load(f)
|
33 |
|
34 |
+
# load models
|
35 |
+
# moneyline
|
36 |
+
model = 'xgboost_ML_no_odds_71.4%'
|
37 |
+
file_path = os.path.join(model_directory, f'{model}.json')
|
38 |
+
xgb_ml = xgb.Booster()
|
39 |
+
xgb_ml.load_model(file_path)
|
40 |
+
|
41 |
+
# over/under
|
42 |
+
model = 'xgboost_OU_no_odds_59.8%'
|
43 |
+
file_path = os.path.join(model_directory, f'{model}.json')
|
44 |
+
xgb_ou = xgb.Booster()
|
45 |
+
xgb_ou.load_model(file_path)
|
46 |
+
|
47 |
+
|
48 |
def get_week():
|
49 |
headers = {
|
50 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
|
62 |
h2_tags = soup.find_all('h2')
|
63 |
year = h2_tags[0].getText().split(' ')[0]
|
64 |
week = h2_tags[0].getText().split(' ')[-1]
|
|
|
65 |
return int(week), int(year)
|
66 |
|
67 |
|
|
|
118 |
|
119 |
# create game id
|
120 |
game_id = str(season) + '_0' + str(week) + '_' + away_abbrev + '_' + home_abbrev
|
121 |
+
print(game_id)
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
try:
|
124 |
moneyline_result = results.loc[results['game_id']==game_id, 'winner'].item()
|
|
|
135 |
moneyline = {'Winner': 'NA',
|
136 |
'Probabilities':['N/A'],
|
137 |
'Result': moneyline_result}
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
try:
|
140 |
result = results.loc[results['game_id']==game_id, 'total'].item()
|