James McCool commited on
Commit
c789832
·
1 Parent(s): 10fff62

added poisson math

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -7,11 +7,13 @@ for name in dir():
7
 
8
  import pulp
9
  import numpy as np
 
10
  import pandas as pd
11
  import streamlit as st
12
  import gspread
13
  import pymongo
14
  from itertools import combinations
 
15
 
16
  @st.cache_resource
17
  def init_conn():
@@ -96,6 +98,13 @@ def pull_baselines():
96
 
97
  return prop_table, prop_trends, pick_frame, timestamp, team_dict
98
 
 
 
 
 
 
 
 
99
  def convert_df_to_csv(df):
100
  return df.to_csv().encode('utf-8')
101
 
@@ -269,16 +278,16 @@ with tab3:
269
  prop_check = (overall_file - prop_file)
270
 
271
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
 
 
272
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
273
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
274
- players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
275
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
276
  players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
277
- players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
278
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
279
  players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
280
- players_only['Prop'] = players_only['Player'].map(prop_dict)
281
- players_only['Book'] = players_only['Player'].map(book_dict)
282
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
283
  players_only['prop_threshold'] = .10
284
  players_only = players_only[players_only['Mean_Outcome'] > 0]
@@ -390,16 +399,17 @@ with tab3:
390
  prop_check = (overall_file - prop_file)
391
 
392
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
 
 
 
393
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
394
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
395
- players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
396
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
397
  players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
398
- players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
399
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
400
  players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
401
- players_only['Prop'] = players_only['Player'].map(prop_dict)
402
- players_only['Book'] = players_only['Player'].map(book_dict)
403
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
404
  players_only['prop_threshold'] = .10
405
  players_only = players_only[players_only['Mean_Outcome'] > 0]
 
7
 
8
  import pulp
9
  import numpy as np
10
+ from numpy import where as np_where
11
  import pandas as pd
12
  import streamlit as st
13
  import gspread
14
  import pymongo
15
  from itertools import combinations
16
+ import scipy.stats as stats
17
 
18
  @st.cache_resource
19
  def init_conn():
 
98
 
99
  return prop_table, prop_trends, pick_frame, timestamp, team_dict
100
 
101
+ def calculate_poisson(row):
102
+ mean_val = row['Mean_Outcome']
103
+ threshold = row['Prop']
104
+ cdf_value = stats.poisson.cdf(threshold, mean_val)
105
+ probability = 1 - cdf_value
106
+ return probability
107
+
108
  def convert_df_to_csv(df):
109
  return df.to_csv().encode('utf-8')
110
 
 
278
  prop_check = (overall_file - prop_file)
279
 
280
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
281
+ players_only['Prop'] = players_only['Player'].map(prop_dict)
282
+ players_only['Book'] = players_only['Player'].map(book_dict)
283
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
284
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
285
+ players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
286
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
287
  players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
288
+ players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
289
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
290
  players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
 
 
291
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
292
  players_only['prop_threshold'] = .10
293
  players_only = players_only[players_only['Mean_Outcome'] > 0]
 
399
  prop_check = (overall_file - prop_file)
400
 
401
  players_only['Mean_Outcome'] = overall_file.mean(axis=1)
402
+ players_only['Prop'] = players_only['Player'].map(prop_dict)
403
+ players_only['Book'] = players_only['Player'].map(book_dict)
404
+ players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
405
  players_only['10%'] = overall_file.quantile(0.1, axis=1)
406
  players_only['90%'] = overall_file.quantile(0.9, axis=1)
407
+ players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
408
  players_only['Imp Over'] = players_only['Player'].map(over_dict)
409
  players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
410
+ players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
411
  players_only['Imp Under'] = players_only['Player'].map(under_dict)
412
  players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
 
 
413
  players_only['Prop_avg'] = players_only['Prop'].mean() / 100
414
  players_only['prop_threshold'] = .10
415
  players_only = players_only[players_only['Mean_Outcome'] > 0]