kyleskom / nba-machine-learning-sports-betting Goto Github PK
View Code? Open in Web Editor NEWNBA sports betting using machine learning
NBA sports betting using machine learning
i keep getting this error when trying to run it
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
2023-02-09 14:05:15.656338: E tensorflow/stream_executor/cuda/cuda_driver.cc:271] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
2023-02-09 14:05:15.656420: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (bb8f3ebcfadd): /proc/driver/nvidia/version does not exist
2023-02-09 14:05:15.656980: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
------------------fanduel odds data------------------
Denver Nuggets (-210) @ Orlando Magic (176)
Phoenix Suns (220) @ Atlanta Hawks (-270)
Chicago Bulls (100) @ Brooklyn Nets (-118)
Milwaukee Bucks (-240) @ Los Angeles Lakers (198)
Traceback (most recent call last):
File "main.py", line 106, in
main()
File "main.py", line 79, in main
data, todays_games_uo, frame_ml, home_team_odds, away_team_odds = createTodaysGames(games, df, odds)
File "main.py", line 52, in createTodaysGames
frame_ml = games_data_frame.drop(columns=['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME'])
File "/usr/local/lib/python3.8/dist-packages/pandas/util/_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/frame.py", line 4906, in drop
return super().drop(
File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 4150, in drop
obj = obj._drop_axis(labels, axis, level=level, errors=errors)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 4214, in _drop_axis
raise KeyError(f"{labels} not found in axis")
KeyError: "['TEAM_ID' 'CFID' 'CFPARAMS' 'TEAM_NAME'] not found in axis"
= RESTART: C:\Users\Dell\Desktop\NBA-Machine-Learning-Sports-Betting\Test\Test_Current_Season.py
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\NBA-Machine-Learning-Sports-Betting\Test\Test_Current_Season.py", line 6, in
model = load_model('../Models/Trained-Model-ML')
File "C:\Python38\lib\site-packages\tensorflow\python\keras\saving\save.py", line 206, in load_model
return saved_model_load.load(filepath, compile, options)
File "C:\Python38\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py", line 121, in load
meta_graph_def = loader_impl.parse_saved_model(path).meta_graphs[0]
File "C:\Python38\lib\site-packages\tensorflow\python\saved_model\loader_impl.py", line 113, in parse_saved_model
raise IOError(
OSError: SavedModel file does not exist at: ../Models/Trained-Model-ML{saved_model.pbtxt|saved_model.pb}
In there there is only a (l('../Models/Trained-Model-ML') file named saved_model.pb
Hi Kyle
This looks really good. I tried running the code and it worked first time. Do I need to update the data in any ways or this is good to go for the rest of this season?
FYI I have no coding experience so just trying to understand how it works. It looks great. Thanks for your work
Take care
Ol
OK, I was able to generate results for 1.17.2022. Can someone please help me interpret this output especially as it relates to the Expected Value calculations.
Thank you!
---------------XGBoost Model Predictions---------------
Atlanta Hawks vs Milwaukee Bucks (65.8%): UNDER 233.5 (54.2%)
Memphis Grizzlies (62.0%) vs Chicago Bulls: UNDER 225.5 (60.1%)
Orlando Magic vs Portland Trail Blazers (69.6%): OVER 193.5 (69.8%)
Los Angeles Lakers vs Utah Jazz (66.6%): OVER 230.5 (51.2%)
Miami Heat (69.5%) vs Toronto Raptors: UNDER 208.5 (53.7%)
Cleveland Cavaliers (60.3%) vs Brooklyn Nets: UNDER 222.5 (61.2%)
LA Clippers (67.4%) vs Indiana Pacers: OVER 209.5 (59.0%)
San Antonio Spurs vs Phoenix Suns (80.0%): UNDER 242.5 (73.8%)
New York Knicks vs Charlotte Hornets (55.9%): OVER 214.5 (67.8%)
Washington Wizards vs Philadelphia 76ers (50.9%): UNDER 221.5 (59.2%)
Boston Celtics (70.3%) vs New Orleans Pelicans: UNDER 213.5 (54.6%)
Dallas Mavericks (82.9%) vs Oklahoma City Thunder: UNDER 215.5 (67.5%)
--------------------Expected Value---------------------
Atlanta Hawks EV: -7.78
Milwaukee Bucks EV: -1.24
Memphis Grizzlies EV: -20.22
Chicago Bulls EV: 42.32
Orlando Magic EV: -34.74
Portland Trail Blazers EV: 19.39
Los Angeles Lakers EV: -1.42
Utah Jazz EV: -6.78
Miami Heat EV: -10.6
Toronto Raptors EV: 9.69
Cleveland Cavaliers EV: -7.91
Brooklyn Nets EV: 1.14
LA Clippers EV: 15.46
Indiana Pacers EV: -29.81
San Antonio Spurs EV: -61.04
Phoenix Suns EV: 49.65
New York Knicks EV: -25.5
Charlotte Hornets EV: 22.99
Washington Wizards EV: 0.58
Philadelphia 76ers EV: -8.32
Boston Celtics EV: 8.31
New Orleans Pelicans EV: -25.77
Dallas Mavericks EV: -9.6
Oklahoma City Thunder EV: 28.52
I found a possible problem in your model inputs.
basically, I think when you scraped the historical team data, for a certain team, at a certain day, the data scrapped has included its current day matches stats.
for example, lets say the nba team data for 11/2/2021, you use that to predict the matches on 11/2/2021. However that nba team data is already including the teams win/lost information on that day.
To me I think this will impact results a lot at season start.
I assume the input for the model should be the team data from previous day. Please check if this is correct.
First of all, great work done. I appreciate your time and efforts put into this. I have a few questions for you:
What python version is the most optimal for the required packages to be installed properly?
Can you elaborate more with examples on what EV is used for and how to interpret the results? I see the first part of the result is the percent chance of winning while the second part is the expected value where it says a number next to each team. I also saw you said the best prediction is to use a positive EV for the pick but what if the team that has positive EV isn't necessarily the predicted team to win in the first part of the result? Can you tell me how EV is calculated as well?
Where is the odds stats provided from in this code? and do you recommend a specific platform to know what the odds and the over/under of the game in interest?
First off, what an awesome model! Downloaded this last night and it worked great. My only issue is with the format on the final results. The coloring isn't showing up so the format is weird and while I can interpret it eventually it's not ideal. I'll attach a screenshot
Is there anyway we could get a spreadsheet output of the results vs the console output?
Also, any plans to apply this to any other sports?
I'm getting error if I use other odds except fanduel
Traceback (most recent call last):
File "main.py", line 104, in
main()
File "main.py", line 66, in main
odds = SbrOddsProvider(sportsbook=args.odds).get_odds()
File "C:\py\NBA2\src\DataProviders\SbrOddsProvider.py", line 30, in get_odds
money_line_home_value = game['home_ml'][self.sportsbook]
KeyError: 'pointsbet'
First off, this is a really cool project and I’m really enjoying going through it.
I do have a few questions however.
The repo includes data all the way back to the 2007-08 season but in the notes, you make reference to “the highest levels of validation accuracy when the training dataset started from the 2012 − 2013 season rather than from the 2007 − 2008 season.”
Can I therefore assume that the model is using only 2012-13 until last year (2021-22) ?
Also wondering what the reason might be for not including games that have already happened this season (2022-23)? Would this not be the most predictive data to use in a model given that players and coaches change teams every year?
I’ve used the Get_data.py script to try and pull this years data after changing the year variables to 2022-23. The script runs well as expected and appears to be pulling data but once it’s finished, I see no output. Looks like it’s supposed to create a new season folder in Team-Data and then populate.
Again, this is really cool and I’m looking forward to seeing how this progresses. Shoutout to those who found a way to integrate different sportsbooks and pull odds. Awesome stuff.
Where did you get the data which is in Odds-Data?
I want to be able to re-create entire dataset
We want to be able to get the odds data automatically without having to manually input data for games.
After installing the packages and running main.py, Python crashes and the terminal outputs a "segmentation fault" error when using the -xgb model:
Using the -nn model does not throw this error. Has anyone else ran into this issue? If so, what did you do in order to get around it?
Here's some additional debugging output:
---------------XGBoost Model Predictions---------------
Fatal Python error: Segmentation fault
Thread 0x000000010319de00 (most recent call first):
File "/Library/Frameworks/Python.framework/Version
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Tensorflow v 2.6.0 cannot be installed via pip or pip3, its not in the available versions
Excause me, I have two questions about this.
First, retrain the model is halpful to improve accuracy? and how to retrain the model. I have run the model in src/Train-Models. But the result seens less obvious.
Second, I got error when I run main.py by input -odds=fanduel. I don't know how the error from.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
2023-01-30 23:32:49.267832: E tensorflow/stream_executor/cuda/cuda_driver.cc:271] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
2023-01-30 23:32:49.267941: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (800dfac52b9b): /proc/driver/nvidia/version does not exist
2023-01-30 23:32:49.268938: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
An error occurred: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "main.py", line 106, in
main()
File "main.py", line 62, in main
odds = SbrOddsProvider(sportsbook=args.odds).get_odds()
File "/content/src/DataProviders/SbrOddsProvider.py", line 13, in init
self.games = Scoreboard(sport="NBA").games
AttributeError: 'Scoreboard' object has no attribute 'games'
#Remove Preexisting Files
! rm -rf NBA-Machine-Learning-Sports-Betting
! rm -rf *
#Bootstrap Files
! git clone https://github.com/kyleskom/NBA-Machine-Learning-Sports-Betting.git
! mv -v ./NBA-Machine-Learning-Sports-Betting/* .
! pip3 install -r requirements.txt
#Clear Bootstrap Logs
from IPython.display import clear_output
clear_output()
print("Successful Bootstrap!!!")
!python3 main.py -A -odds=fanduel
Hi, kyle, i'm getting this error, since i have no coding EXP, i don't know where goes wrong. Can you see the problem?
(base) C:\Users\zybxixi>C:\Users\zybxixi\Desktop\NBA-Machine-Learning-Sports-Betting-master\main.py
Traceback (most recent call last):
File "C:\Users\zybxixi\Desktop\NBA-Machine-Learning-Sports-Betting-master\main.py", line 4, in
from src.Predict import NN_Runner, XGBoost_Runner
File "C:\Users\zybxixi\Desktop\NBA-Machine-Learning-Sports-Betting-master\src\Predict\NN_Runner.py", line 8, in
model = load_model('Models/NN_Models/Trained-Model-ML')
File "C:\Users\zybxixi\anaconda3\lib\site-packages\tensorflow\python\keras\saving\save.py", line 186, in load_model
loader_impl.parse_saved_model(filepath)
File "C:\Users\zybxixi\anaconda3\lib\site-packages\tensorflow\python\saved_model\loader_impl.py", line 110, in parse_saved_model
raise IOError("SavedModel file does not exist at: %s/{%s|%s}" %
OSError: SavedModel file does not exist at: Models/NN_Models/Trained-Model-ML/{saved_model.pbtxt|saved_model.pb}
I know it is entirely on my end but I do not know how to fix this issue. I have tried updating to the newest tensorflow and I have tried changing python versions on my visual studio code. I do not know if I did not change the python versions correctly or what I need todo to fix this. Any help would be appreciated. Thank you!
after four grueling months to finally get Tensorflow and all the dependencies installed ... this is the result of running the program for 6 days.....?????????????? ready to give up and move on. it seems impossible to use other people's python programs....! Worst language ever in this regard .!!!!
anyway here is the error message...?
FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
stats = home_team_series.append(away_team_series)
Chicago Bulls vs Minnesota Timberwolves: 241.5
Chicago Bulls odds: -3.5
Minnesota Timberwolves odds: 3.5
/Users/adamarie/Desktop/NBA-Machine-Learning-Sports-Betting-master/main.py:35: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
stats = home_team_series.append(away_team_series)
Utah Jazz vs Orlando Magic: 222.5
Utah Jazz odds: -13.5
Orlando Magic odds: 13.5
/Users/adamarie/Desktop/NBA-Machine-Learning-Sports-Betting-master/main.py:35: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
stats = home_team_series.append(away_team_series)
---------------XGBoost Model Predictions---------------
zsh: segmentation fault python3 main.py -xgb
crash, crash, and crash!!
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
2023-01-31 00:52:00.517732: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-01-31 00:52:01.116627: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
2023-01-31 00:52:01.116689: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 38428 MB memory: -> device: 0, name: NVIDIA A100-SXM4-40GB, pci bus id: 0000:00:04.0, compute capability: 8.0
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
Minnesota Timberwolves vs Sacramento Kings:
I am getting the following stack trace when I run your example:
root@ubuntu:~/NBA-Machine-Learning-Sports-Betting# python3 main.py -xgb
2021-12-23 18:21:52.542420: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-12-23 18:21:52.542477: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-12-23 18:21:54.185237: E tensorflow/core/lib/monitoring/collection_registry.cc:77] Cannot register 2 metrics with the same name: /tensorflow/api/keras/optimizers
Traceback (most recent call last):
File "main.py", line 4, in
from src.Predict import NN_Runner, XGBoost_Runner
File "/root/NBA-Machine-Learning-Sports-Betting/src/Predict/NN_Runner.py", line 6, in
from tensorflow.keras.models import load_model
File "/usr/local/lib/python3.8/dist-packages/keras/api/_v2/keras/init.py", line 10, in
from keras import version
File "/usr/local/lib/python3.8/dist-packages/keras/init.py", line 25, in
from keras import models
File "/usr/local/lib/python3.8/dist-packages/keras/models.py", line 20, in
from keras import metrics as metrics_module
File "/usr/local/lib/python3.8/dist-packages/keras/metrics.py", line 26, in
from keras import activations
File "/usr/local/lib/python3.8/dist-packages/keras/activations.py", line 20, in
from keras.layers import advanced_activations
File "/usr/local/lib/python3.8/dist-packages/keras/layers/init.py", line 23, in
from keras.engine.input_layer import Input
File "/usr/local/lib/python3.8/dist-packages/keras/engine/input_layer.py", line 21, in
from keras.engine import base_layer
File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer.py", line 43, in
from keras.mixed_precision import loss_scale_optimizer
File "/usr/local/lib/python3.8/dist-packages/keras/mixed_precision/loss_scale_optimizer.py", line 18, in
from keras import optimizers
File "/usr/local/lib/python3.8/dist-packages/keras/optimizers.py", line 26, in
from keras.optimizer_v2 import adadelta as adadelta_v2
File "/usr/local/lib/python3.8/dist-packages/keras/optimizer_v2/adadelta.py", line 22, in
from keras.optimizer_v2 import optimizer_v2
File "/usr/local/lib/python3.8/dist-packages/keras/optimizer_v2/optimizer_v2.py", line 36, in
keras_optimizers_gauge = tf.internal.monitoring.BoolGauge(
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/monitoring.py", line 360, in init
super(BoolGauge, self).init('BoolGauge', _bool_gauge_methods,
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/monitoring.py", line 135, in init
self._metric = self._metric_methods[self._label_length].create(*args)
tensorflow.python.framework.errors_impl.AlreadyExistsError: Another metric with the same name already exists.
run in google colab,
!python3 main.py -xgb -odds=fanduel
is ok.
but ---------
!python3 main.py -A -odds=fanduel
is faild. always running ,not result....
When I run python3 main.py -xgb, I expected to get output of results, however, it seems to just read the games via (create_todays_games) and stop there.
Any idea on what may be stopping the results from being calculated?
Hi!
I wanted to know few things, from my understanding the odds do not change the % of the calculation of the moneyline winner correct?
Also recent games effect the moneyline prediction correct?
if that's the case i wanted to know if there's a way to get the predictions from the beginning of the season, i wanted to check the algorithm results for the whole current and last year season. just winning percentage (without odds).
There are many updates and improvements still in the pipeline. As the NBA season comes to a close, there won't be any time to test these changes. Expect many updates and improvements for the 2021-2022 season!
I am looking for feedback and suggestions. Please leave an issue below for improvements and features that you would like to see!
I can't go further as I run "python3 main.py -xgb -odds=fanduel" and i got "python could not be found. execute with no arguments to proceed to the ó l"
Is there a way to pull data in from the current season 2021-22? Sorry for the basic question, appreciate any insights you can provide
File "main.py", line 106, in
main()
File "main.py", line 79, in main
data, todays_games_uo, frame_ml, home_team_odds, away_team_odds = createTodaysGames(games, df, odds)
File "main.py", line 52, in createTodaysGames
frame_ml = games_data_frame.drop(columns=['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME'])
File "/usr/local/lib/python3.8/dist-packages/pandas/util/_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/frame.py", line 4906, in drop
return super().drop(
File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 4150, in drop
obj = obj._drop_axis(labels, axis, level=level, errors=errors)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 4214, in _drop_axis
raise KeyError(f"{labels} not found in axis")
KeyError: "['TEAM_ID' 'CFID' 'CFPARAMS' 'TEAM_NAME'] not found in axis"
when the execution of main.py file completes
it shows team names like
Indiana Pacers vs Washington Wizards : __________
Now what input should i give in this ?
How to give input
Please show with an example
that would be very helpful , sir
Hey, first time compiling it, i have this issue says connection aborted? maybe its because of my ip? im not from US, fanduels website loads fine from my country it seems. maybe can you add proxy support? or is it something else
thank you in advance
2023-01-26 04:26:26.655251: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2023-01-26 04:26:26.655265: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), *NOT* tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
2023-01-26 04:26:27.175789: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2023-01-26 04:26:27.175802: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2023-01-26 04:26:27.175811: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (GAMING): /proc/driver/nvidia/version does not exist
2023-01-26 04:26:27.175909: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), *NOT* tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/xgboost/compat.py:31: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
from pandas import MultiIndex, Int64Index
Traceback (most recent call last):
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
response.begin()
File "/usr/lib/python3.8/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.8/http/client.py", line 277, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/packages/six.py", line 769, in reraise
raise value.with_traceback(tb)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
response.begin()
File "/usr/lib/python3.8/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.8/http/client.py", line 277, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 104, in <module>
main()
File "main.py", line 63, in main
data = get_json_data(data_url)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/src/Utils/tools.py", line 28, in get_json_data
raw_data = requests.get(url, headers=data_headers)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/gaming/Desktop/pythonprojects/NBA-Machine-Learning-Sports-Betting/venv/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Hey Kyle,
Thanks a ton for all your work creating this.
When running: ! python3 /content/NBA-Machine-Learning-Sports-Betting/main.py -xgb -odds=fanduel
I'm getting a numpy error that says:
File "/usr/local/lib/python3.8/dist-packages/numpy/init.py", line 284, in __ getattr __
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'object'
I can't figure out this error, has anyone ran into anything like this before?
An error occurred: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "main.py", line 106, in
main()
File "main.py", line 62, in main
odds = SbrOddsProvider(sportsbook=args.odds).get_odds()
File "/content/src/DataProviders/SbrOddsProvider.py", line 13, in init
self.games = Scoreboard(sport="NBA").games
AttributeError: 'Scoreboard' object has no attribute 'games'
Not sure, what seems to be going on?
Has the "sbrscrape" library changed and the "games" attribute is no longer available?
Or Is there a mistake in the import statement or in the use of the library?
Wow thank you for this interesting project.
I just wanted to check it out, but i'm not sure how to enter today's games under/over data.
Do you have a example?
It asks me: Charlotte Hornets vs Houston Rockets:
Any insight for beginners how to consistently train the model with new data for the current season?
Is the players stats and teams stats automatically updated from the last day?
How can I feed the data even more information?
Any ideas on converting existing model to NCAAB?
Hello @kyleskom .
First, as a ML beginner, I learned so much from your project. Many thanks.
I gathered data from 2007-08 to 2021-22 seasons and made a full dataset.
and trained both Xgboost and NN model, result was awesome.
Currently my model predicted 55 games so far and result is presented below table.
| —— | Away Win | Home Win | Under | Over |
| Xgb | 75.0% | 83.9% | 71.4% | 77.8% |
| NN | 64.5% | 87.5% | 72.2% | 64.9% |
I think this result is excessively high so I assume that I did something wrong during training model or making dataset.
If you can check my forked repo and tell me your thoughts, It would be greatful.
I'm just doing this by searching from google & stackoverflow so I am not sure what's the problem ...
Have a great day!
https://github.com/Jojorabbit21/NBA-Machine-Learning-Sports-Betting
Started scrip
root@osboxes:/home/osboxes/NBA-Machine-Learning-Sports-Betting# python3 main.py -xgb
2021-11-01 21:56:48.731620: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-11-01 21:56:48.731730: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
2021-11-01 21:56:49.811503: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-11-01 21:56:49.811537: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2021-11-01 21:56:49.811582: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (osboxes): /proc/driver/nvidia/version does not exist
2021-11-01 21:56:49.811768: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
Paste data
Charlotte Hornets vs Cleveland Cavaliers: 216
Charlotte Hornets odds: 1.512
Cleveland Cavaliers odds: 2.82
Indiana Pacers vs San Antonio Spurs: 219.5
Indiana Pacers odds: 1.782
San Antonio Spurs odds: 2.522
Philadelphia 76ers vs Portland Trail Blazers: 220.5
Philadelphia 76ers odds: 1.815
Portland Trail Blazers odds: 2.155
Atlanta Hawks vs Washington Wizards: 221.5
Atlanta Hawks odds: 1.558
Washington Wizards odds: 3.165
Boston Celtics vs Chicago Bulls: 218.5
Boston Celtics odds: 1.842
Chicago Bulls odds: 2.41
New York Knicks vs Toronto Raptors: 208.5
New York Knicks odds: 1.44
Toronto Raptors odds: 3.7
Memphis Grizzlies vs Denver Nuggets: 213.5
Memphis Grizzlies odds: 2.04
Denver Nuggets odds: 1.93
Minnesota Timberwolves vs Orlando Magic: 216.5
Minnesota Timberwolves odds: 1.31
Orlando Magic odds: 4.76
LA Clippers vs Oklahoma City Thunder: 213
LA Clippers odds: 1.16
Oklahoma City Thunder odds: 8
Got prediction
---------------XGBoost Model Predictions---------------
Charlotte Hornets (84.1%) vs Cleveland Cavaliers: OVER 216 (59.8%)
Indiana Pacers vs San Antonio Spurs (55.2%): OVER 219.5 (68.9%)
Philadelphia 76ers (76.7%) vs Portland Trail Blazers: OVER 220.5 (66.4%)
Atlanta Hawks vs Washington Wizards (77.3%): UNDER 221.5 (68.3%)
Boston Celtics vs Chicago Bulls (81.9%): UNDER 218.5 (59.0%)
New York Knicks (92.0%) vs Toronto Raptors: UNDER 208.5 (72.4%)
Memphis Grizzlies vs Denver Nuggets (63.9%): OVER 213.5 (58.4%)
Minnesota Timberwolves (92.1%) vs Orlando Magic: UNDER 216.5 (73.5%)
LA Clippers (64.0%) vs Oklahoma City Thunder: UNDER 213 (75.6%)
Got error here
--------------------Expected Value---------------------
Traceback (most recent call last):
File "/home/osboxes/NBA-Machine-Learning-Sports-Betting/main.py", line 79, in
main()
File "/home/osboxes/NBA-Machine-Learning-Sports-Betting/main.py", line 61, in main
XGBoost_Runner.xgb_runner(data, todays_games_uo, frame_ml, games, home_team_odds, away_team_odds)
File "/home/osboxes/NBA-Machine-Learning-Sports-Betting/src/Predict/XGBoost_Runner.py", line 79, in xgb_runner
ev_home = float(Expected_Value.expected_value(ml_predictions_array[count][0][1], int(home_team_odds[count])))
ValueError: invalid literal for int() with base 10: '1.512'
I have the same issue when using fanduel or any other. But it first worked, then after some time it stopped working and the error came.
I run this: !python3 main.py -A -odds=fanduel
It was working hours ago. I got results and everything was fine. I have changed nothing and then this error appeared after trying to make the call again:
Traceback (most recent call last):
File "main.py", line 104, in
main()
File "main.py", line 66, in main
odds = SbrOddsProvider(sportsbook=args.odds).get_odds()
File "/content/src/DataProviders/SbrOddsProvider.py", line 30, in get_odds
money_line_home_value = game['home_ml'][self.sportsbook]
KeyError: 'fanduel'
Same problem with all args
I am testing:
In theory these two data sets should be exactly matched, but I see that the excel file created by get_data.py seems not correct.
attached is the excel file I created for 04/03/2022, using get_data.py.
4-3-2021-22.xlsx
The win lost numbers are different from the actual current league stats.
I doubt if this is some issue from my running procedure, or the request url. I can't tell at this moment.
Another suggestion is that nba_api is a very good package to download the nba team stats, which can be considered.
Hey
Can you share some documentation link for this api?
"'https://data.nba.com/data/10s/v2015/json/mobile_teams/nba/2021/scores/00_todays_scores.json"
I am trying to test the api on a given date, this gives empty response because there were no matches today but I need the docs so I can put in a date and test my pipeline
HI when i launch the main.py i have this error message : OSError: No file or directory found at Models/NN_Models/Trained-Model-ML
what is the problem ? thank you
Need to add a requirements.txt file to this project.
The data_url you use in main.py does not seem to work:
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=2021-22&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&'
'StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision='
When I try it running your program it just hangs, and same when when I enter this into my browser:
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=2021-22&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision=
Downloaded and launched today - 01.11.2021 at 13.55(UTC).
The script prompts you to fill in the data for:
Dallas Mavericks vs Sacramento Kings
Charlotte Hornets vs Portland Trail Blazers
Los Angeles Lakers vs Houston Rockets
Milwaukee Bucks vs Utah Jazz
Brooklyn Nets vs Detroit Pistons.
All of these games are already over.
How do I run predictions for upcoming games?
Switch from storing data inside excel sheets to a database. Need to refactor get_data to save to database and refactor to read from database
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.