Spaces:
Running
Running
James McCool
commited on
Commit
·
fb1703c
1
Parent(s):
ba1b862
added poisson calc, reintroduced 3-pointers
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ for name in dir():
|
|
| 6 |
del globals()[name]
|
| 7 |
|
| 8 |
import numpy as np
|
|
|
|
| 9 |
import pandas as pd
|
| 10 |
import streamlit as st
|
| 11 |
import gspread
|
|
@@ -13,6 +14,7 @@ import plotly.express as px
|
|
| 13 |
import pymongo
|
| 14 |
import random
|
| 15 |
import gc
|
|
|
|
| 16 |
from datetime import datetime
|
| 17 |
|
| 18 |
@st.cache_resource
|
|
@@ -67,6 +69,13 @@ all_sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_
|
|
| 67 |
pick6_sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds']
|
| 68 |
sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def add_column(df):
|
| 71 |
return_df = df
|
| 72 |
return_df['2P'] = return_df["Minutes"] * return_df["FG2M"]
|
|
@@ -412,9 +421,10 @@ with tab5:
|
|
| 412 |
key='prop_source',
|
| 413 |
)
|
| 414 |
if game_select_var == 'Aggregate':
|
| 415 |
-
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS',
|
|
|
|
| 416 |
elif game_select_var == 'Pick6':
|
| 417 |
-
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds'])
|
| 418 |
|
| 419 |
if st.button('Simulate Prop Category'):
|
| 420 |
with col2:
|
|
@@ -423,10 +433,11 @@ with tab5:
|
|
| 423 |
if prop_type_var == 'All Props':
|
| 424 |
if game_select_var == 'Aggregate':
|
| 425 |
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 426 |
-
sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS',
|
|
|
|
| 427 |
elif game_select_var == 'Pick6':
|
| 428 |
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 429 |
-
sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds']
|
| 430 |
|
| 431 |
player_df = player_stats.copy()
|
| 432 |
|
|
@@ -505,16 +516,17 @@ with tab5:
|
|
| 505 |
prop_check = (overall_file - prop_file)
|
| 506 |
|
| 507 |
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
|
|
|
|
|
|
|
|
|
| 508 |
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 509 |
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 510 |
-
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 511 |
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 512 |
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 513 |
-
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 514 |
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 515 |
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 516 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 517 |
-
players_only['Book'] = players_only['Player'].map(book_dict)
|
| 518 |
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 519 |
players_only['prop_threshold'] = .10
|
| 520 |
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
|
@@ -650,16 +662,17 @@ with tab5:
|
|
| 650 |
prop_check = (overall_file - prop_file)
|
| 651 |
|
| 652 |
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
|
|
|
|
|
|
|
|
|
| 653 |
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 654 |
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 655 |
-
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 656 |
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 657 |
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 658 |
-
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 659 |
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 660 |
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 661 |
-
players_only['Book'] = players_only['Player'].map(book_dict)
|
| 662 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 663 |
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 664 |
players_only['prop_threshold'] = .10
|
| 665 |
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
|
|
|
| 6 |
del globals()[name]
|
| 7 |
|
| 8 |
import numpy as np
|
| 9 |
+
from numpy import where as np_where
|
| 10 |
import pandas as pd
|
| 11 |
import streamlit as st
|
| 12 |
import gspread
|
|
|
|
| 14 |
import pymongo
|
| 15 |
import random
|
| 16 |
import gc
|
| 17 |
+
import scipy.stats as stats
|
| 18 |
from datetime import datetime
|
| 19 |
|
| 20 |
@st.cache_resource
|
|
|
|
| 69 |
pick6_sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds']
|
| 70 |
sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
| 71 |
|
| 72 |
+
def calculate_poisson(row):
|
| 73 |
+
mean_val = row['Mean_Outcome']
|
| 74 |
+
threshold = row['Prop']
|
| 75 |
+
cdf_value = stats.poisson.cdf(threshold, mean_val)
|
| 76 |
+
probability = 1 - cdf_value
|
| 77 |
+
return probability
|
| 78 |
+
|
| 79 |
def add_column(df):
|
| 80 |
return_df = df
|
| 81 |
return_df['2P'] = return_df["Minutes"] * return_df["FG2M"]
|
|
|
|
| 421 |
key='prop_source',
|
| 422 |
)
|
| 423 |
if game_select_var == 'Aggregate':
|
| 424 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS',
|
| 425 |
+
'NBA_GAME_PLAYER_POINTS_REBOUNDS', 'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_3_POINTERS_MADE'])
|
| 426 |
elif game_select_var == 'Pick6':
|
| 427 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds', '3-Pointers Made'])
|
| 428 |
|
| 429 |
if st.button('Simulate Prop Category'):
|
| 430 |
with col2:
|
|
|
|
| 433 |
if prop_type_var == 'All Props':
|
| 434 |
if game_select_var == 'Aggregate':
|
| 435 |
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 436 |
+
sim_vars = ['NBA_GAME_PLAYER_POINTS', 'NBA_GAME_PLAYER_REBOUNDS', 'NBA_GAME_PLAYER_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_POINTS_REBOUNDS',
|
| 437 |
+
'NBA_GAME_PLAYER_POINTS_ASSISTS', 'NBA_GAME_PLAYER_REBOUNDS_ASSISTS', 'NBA_GAME_PLAYER_3_POINTERS_MADE']
|
| 438 |
elif game_select_var == 'Pick6':
|
| 439 |
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 440 |
+
sim_vars = ['Points', 'Rebounds', 'Assists', 'Points + Assists + Rebounds', 'Points + Assists', 'Points + Rebounds', 'Assists + Rebounds', '3-Pointers Made']
|
| 441 |
|
| 442 |
player_df = player_stats.copy()
|
| 443 |
|
|
|
|
| 516 |
prop_check = (overall_file - prop_file)
|
| 517 |
|
| 518 |
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 519 |
+
players_only['Book'] = players_only['Player'].map(book_dict)
|
| 520 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 521 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
| 522 |
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 523 |
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 524 |
+
players_only['Over'] = np_where(overall_file['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
| 525 |
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 526 |
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 527 |
+
players_only['Under'] = np_where(overall_file['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
| 528 |
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 529 |
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
|
|
|
|
|
|
| 530 |
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 531 |
players_only['prop_threshold'] = .10
|
| 532 |
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
|
|
|
| 662 |
prop_check = (overall_file - prop_file)
|
| 663 |
|
| 664 |
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 665 |
+
players_only['Book'] = players_only['Player'].map(book_dict)
|
| 666 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 667 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
| 668 |
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 669 |
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 670 |
+
players_only['Over'] = np_where(overall_file['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
| 671 |
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 672 |
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 673 |
+
players_only['Under'] = np_where(overall_file['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
| 674 |
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 675 |
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
|
|
|
|
|
|
| 676 |
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 677 |
players_only['prop_threshold'] = .10
|
| 678 |
players_only = players_only[players_only['Mean_Outcome'] > 0]
|