kyleskom / NBA-Machine-Learning-Sports-Betting

NBA sports betting using machine learning
1.13k stars 425 forks source link

KeyError: "['TEAM_ID' 'CFID' 'CFPARAMS' 'TEAM_NAME'] not found in axis" #84

Closed nickmalbsn closed 1 year ago

nickmalbsn commented 1 year ago

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"

nickmalbsn commented 1 year ago

someone had this issue and said to do this

you can do a temporary quick fix in the main.py file:

change this line (line 52) frame_ml = games_data_frame.drop(columns=['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME'])

to

columns_to_drop = ['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME'] existing_columns = games_data_frame.columns columns_to_drop = list(set(columns_to_drop).intersection(existing_columns)) frame_ml = games_data_frame.drop(columns=columns_to_drop)

i did that and now i get this issue

File "main.py", line 56 data = frame_ml.values ^ IndentationError: unexpected indent

MM131393 commented 1 year ago

The change to line 52 worked.

Thanks for sharing this.

512jay commented 1 year ago

someone had this issue and said to do this

you can do a temporary quick fix in the main.py file:

change this line (line 52) frame_ml = games_data_frame.drop(columns=['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME'])

to:

columns_to_drop = ['TEAM_ID', 'CFID', 'CFPARAMS', 'TEAM_NAME']
existing_columns = games_data_frame.columns
columns_to_drop = list(set(columns_to_drop).intersection(existing_columns))
frame_ml = games_data_frame.drop(columns=columns_to_drop)

Did indeed provide a fix for me also.

Gzakko commented 1 year ago

hello, completely new to coding and getting the same error, ive been using this for the past 4 days with great success while betting, thank you for the hard work everyone has put in, but cant seem to edit line 52 , i found main.py file i've download it but cant open it. any help is appreciated, thank you

Gzakko commented 1 year ago

figured it out, i had to double click "main.py" and just copy paste at line 52 and works . thank you!

edit: my question is do i have to insert the new line manually everytime, cant seem to save it

512jay commented 1 year ago

Curious,

How have you achieved great success?

Jay Davis

On Thu, Feb 9, 2023 at 12:11 PM Gzakko @.***> wrote:

figured it out, i had to double click "main.py" and just copy paste at line 52 and works . thank you!

— Reply to this email directly, view it on GitHub https://github.com/kyleskom/NBA-Machine-Learning-Sports-Betting/issues/84#issuecomment-1424533059, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOJHTET6S67HNBGTZAIXADWWUQMZANCNFSM6AAAAAAUWWD3EM . You are receiving this because you commented.Message ID: @.*** com>

gwhnhs commented 1 year ago

changing line 52 worked for me too, but only for the XGB and eV.

my neural network model says:

2023-02-09 13:38:02.410865: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2) zsh: segmentation fault python3 main.py -A -odds=draftkings

help please thanks.

JackB2003 commented 1 year ago

I updated 'Line 52' as well and it worked! Thank you!

I am still seeing an error, that doesnt affect the results, but still would like to know if there has been fix for it. See below...

**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 18:36:22.174047: 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 18:36:22.174112: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (b9a1c6b6e59e): /proc/driver/nvidia/version does not exist
2023-02-09 18:36:22.175409: 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 (-240) @ Orlando Magic (198) Phoenix Suns (220) @ Atlanta Hawks (-270) Chicago Bulls (100) @ Brooklyn Nets (-118) Milwaukee Bucks (-310) @ Los Angeles Lakers (250)

XGBoost Model Predictions Orlando Magic vs Denver Nuggets (74.8%): UNDER 231.5 (52.1%) Atlanta Hawks vs Phoenix Suns (57.9%): OVER 228.5 (54.8%) Brooklyn Nets (73.6%) vs Chicago Bulls: OVER 226.5 (53.0%) Los Angeles Lakers vs Milwaukee Bucks (66.2%): UNDER 238.5 (70.3%)

Expected Value: Orlando Magic EV: -24.81 Denver Nuggets EV: 5.92 Atlanta Hawks EV: -42.25 Phoenix Suns EV: 85.14 Brooklyn Nets EV: 35.91 Chicago Bulls EV: -47.13 Los Angeles Lakers EV: 18.46 Milwaukee Bucks EV: -12.5

Neural Network Model Predictions

**2023-02-09 18:36:25.205142: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR**_ 
Optimization Passes are enabled (registered 2)

Orlando Magic vs Denver Nuggets (74.2%): UNDER 231.5 (54.8%) Atlanta Hawks vs Phoenix Suns (55.5%): UNDER 228.5 (49.1%) Brooklyn Nets (77.0%) vs Chicago Bulls: UNDER 226.5 (50.3%) Los Angeles Lakers vs Milwaukee Bucks (74.8%): OVER 238.5 (51.8%)

Expected Value Orlando Magic EV: -23.11 Denver Nuggets EV: 5.11 Atlanta Hawks EV: -38.97 Phoenix Suns EV: 77.49 Brooklyn Nets EV: 42.25 Chicago Bulls EV: -54.0 Los Angeles Lakers EV: -11.73 Milwaukee Bucks EV: -1.1

JackB2003 commented 1 year ago

On a small scale, just 10-20$ bets Been averaging both xgboost and neural and not taking anything under aprox 70% for the moneyline. As for the o/u im still trying to figure out the best approach but seems like the neural only % above 54-55% seems to be working, im not placing bets on everything just keeping track the past few days How’s it looking for you? What’s your strategy Get Outlook for iOShttps://aka.ms/o0ukef


I only have a VERY small sample size (yesterday lol), but as of right now, this is what Im looking at.

XGBoost: Went 6-3 on 2/8/23 assuming you bet on all games.

Neural Network: Went 6-3 on 2/8/23 assuming you bet on all games.

Neural Network seems like the best way to go, but XGBoost should provide some good info as well. Again - this is a VERY VERY VERY small sample size. Once the sample size grows, Im hoping to see more trends.

levski87 commented 1 year ago

Thanks for all the help here on fixing the issue. Oddly enough, its a bit sporadic and comes and goes without even taking action. Either way, will try this next time.

@JackB2003 - Would be interested to see the Over/Unders and how well each model predicts it.

@kyleskom - For clarification here, few questions:

  1. Have you trained this model up until the end of the 2021 season? If further, how much?
  2. Does the model automatically adjust based on the games played over the course of this season?
  3. Is the model only trained on team based statistics (ex: team ppg, rebounds per game), or does it include player based attributes.
kyleskom commented 1 year ago

1.) I forgot when I tried the model too. It's a few years old. 2.) No, model would need to be recreated 3.) Only team data, always wanted to add players data but never enough time currently to do so.

levski87 commented 1 year ago

Thank you, very helpful.

If I wanted to train it up to the most current season and day, do I simply need to update the excel files in the Team Data folder?

kyleskom commented 1 year ago

Yes, using the get_data file

gwhnhs commented 1 year ago

where did you find the team data online?

would you join the team data and player data tables, or would you create new excel sheets for the players?

levski87 commented 1 year ago

Same question as above, willing to help update the data here with the latest and greatest if I knew how and where you sourced it from.

kyleskom commented 1 year ago

https://github.com/kyleskom/NBA-Machine-Learning-Sports-Betting/blob/master/src/Process-Data/Get_Data.py

Data is coming from https://www.nba.com/stats

nickmalbsn commented 1 year ago

https://github.com/kyleskom/NBA-Machine-Learning-Sports-Betting/blob/master/src/Process-Data/Get_Data.py

Data is coming from https://www.nba.com/stats

is there a way to add different sports like hockey, soccer, baseball, etc. to this? i am brand new to coding so idk how this works lol

kyleskom commented 1 year ago

https://github.com/kyleskom/NBA-Machine-Learning-Sports-Betting/blob/master/src/Process-Data/Get_Data.py Data is coming from https://www.nba.com/stats

is there a way to add different sports like hockey, soccer, baseball, etc. to this? i am brand new to coding so idk how this works lol

Unfortunately not, thats not how these kinds of things work. If you're interested in learning about it look into supervised machine learning.

gwhnhs commented 1 year ago

players on NBA teams change so frequently that in order for this to be accurate the stats really need to be updated thru last night's games

kyleskom commented 1 year ago

Thanks for pointing out the obvious. It's something I have talked about in threads scattered all across this repo. I am open to PR's with this.

kyleskom commented 1 year ago

Fixed #85