Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
__pycache__/
*.py[cod]
*$py.class

#Saved models
randomForestModelTuned.joblib
# C extensions
*.so

Expand Down
Binary file modified FeatureImportance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __pycache__/nba_web_scraper.cpython-310.pyc
Binary file not shown.
56,850 changes: 29,015 additions & 27,835 deletions all_data_regressor.csv
100644 → 100755

Large diffs are not rendered by default.

Binary file modified correlations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
605 changes: 358 additions & 247 deletions nba_ml.py
100644 → 100755

Large diffs are not rendered by default.

77 changes: 73 additions & 4 deletions nba_web_scraper.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@
from os.path import join, exists
from os import getcwd

def html_to_df_web_scrape_NBA(URL,team,year):
def html_to_df_web_scrape_NBA(URL,URL1,team,year):
while True:
try:
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
page1 = requests.get(URL1)
soup1 = BeautifulSoup(page1.content, "html.parser")
break
except:
print('HTTPSConnectionPool(host="www.sports-reference.com", port=443): Max retries exceeded. Retry in 10 seconds')
sleep(10)
table = soup.find(id="all_tgl_basic")
table1 = soup1.find(id="all_tgl_advanced")
tbody = table.find('tbody')
tbody1 = table1.find('tbody')
tr_body = tbody.find_all('tr')
tr_body1 = tbody1.find_all('tr')
# game_season = []
# date_game = []
# game_location = []
# opp_id= []
# BASIC STATS
game_result= []
pts= []
opp_pts= []
Expand Down Expand Up @@ -138,14 +144,77 @@ def html_to_df_web_scrape_NBA(URL,team,year):
if td.get('data-stat') == "opp_tov":
opp_tov.append(td.get_text())
if td.get('data-stat') == "opp_pf":
opp_pf.append(td.get_text())
opp_pf.append(td.get_text())
#ADVANCED STATS
off_rtg = []
def_rtg = []
pace = []
fta_per_fga_pct = []
fg3a_per_fga_pct = []
ts_pct = []
trb_pct = []
ast_pct = []
stl_pct = []
blk_pct = []
efg_pct = []
tov_pct = []
orb_pct = []
ft_rate = []
opp_efg_pct= []
opp_tov_pct = []
drb_pct = []
opp_ft_rate = []
for trb in tr_body1:
for td in trb.find_all('td'):
if td.get('data-stat') == "off_rtg":
off_rtg.append(td.get_text())
if td.get('data-stat') == "def_rtg":
def_rtg.append(td.get_text())
if td.get('data-stat') == "pace":
pace.append(td.get_text())
if td.get('data-stat') == "fta_per_fga_pct":
fta_per_fga_pct.append(td.get_text())
if td.get('data-stat') == "fg3a_per_fga_pct":
fg3a_per_fga_pct.append(td.get_text())
if td.get('data-stat') == "ts_pct":
ts_pct.append(td.get_text())
if td.get('data-stat') == "trb_pct":
trb_pct.append(td.get_text())
if td.get('data-stat') == "ast_pct":
ast_pct.append(td.get_text())
if td.get('data-stat') == "stl_pct":
stl_pct.append(td.get_text())
if td.get('data-stat') == "blk_pct":
blk_pct.append(td.get_text())
if td.get('data-stat') == "efg_pct":
efg_pct.append(td.get_text())
if td.get('data-stat') == "tov_pct":
tov_pct.append(td.get_text())
if td.get('data-stat') == "orb_pct":
orb_pct.append(td.get_text())
if td.get('data-stat') == "ft_rate":
ft_rate.append(td.get_text())
if td.get('data-stat') == "opp_efg_pct":
opp_efg_pct.append(td.get_text())
if td.get('data-stat') == "opp_tov_pct":
opp_tov_pct.append(td.get_text())
if td.get('data-stat') == "drb_pct":
drb_pct.append(td.get_text())
if td.get('data-stat') == "opp_ft_rate":
opp_ft_rate.append(td.get_text())


return DataFrame(list(zip(game_result,pts,opp_pts,fg,fga,
fg_pct,fg3,fg3a,fg3_pct,ft,fta,ft_pct,orb,total_board,ast,
stl,blk,tov,pf,opp_fg,opp_fga,opp_fg_pct,opp_fg3,opp_fg3a,opp_fg3_pct,
opp_ft,opp_fta,opp_ft_pct,opp_orb,opp_trb,opp_ast,opp_stl,opp_blk,opp_tov,
opp_pf)),
opp_pf, off_rtg,def_rtg,pace,fta_per_fga_pct,fg3a_per_fga_pct,ts_pct,
trb_pct,ast_pct,stl_pct,blk_pct,efg_pct,tov_pct,orb_pct,ft_rate,opp_efg_pct,
opp_tov_pct,drb_pct,opp_ft_rate)),
columns =['game_result','pts','opp_pts','fg','fga',
'fg_pct','fg3','fg3a','fg3_pct','ft','fta','ft_pct','orb','total_board','ast',
'stl','blk','tov','pf','opp_fg','opp_fga','opp_fg_pct','opp_fg3','opp_fg3a','opp_fg3_pct',
'opp_ft','opp_fta','opp_ft_pct','opp_orb','opp_trb','opp_ast','opp_stl','opp_blk','opp_tov',
'opp_pf'])
'opp_pf','off_rtg','def_rtg','pace','fta_per_fga_pct','fg3a_per_fga_pct','ts_pct',
'trb_pct','ast_pct','stl_pct','blk_pct','efg_pct','tov_pct','orb_pct','ft_rate','opp_efg_pct',
'opp_tov_pct','drb_pct','opp_ft_rate'])
Binary file modified prob_plots_regress/probplot_ast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added prob_plots_regress/probplot_ast_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_blk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_fg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_fg3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_fg3_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_fg_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_fga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_ft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_ft_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_game_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added prob_plots_regress/probplot_off_rtg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_ast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_blk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_fg3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_fg3_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_fg_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_fga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_ft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_ft_pct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_orb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_pf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_pts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified prob_plots_regress/probplot_opp_stl.png
Binary file modified prob_plots_regress/probplot_opp_tov.png
Binary file modified prob_plots_regress/probplot_opp_trb.png
Binary file modified prob_plots_regress/probplot_orb.png
Binary file added prob_plots_regress/probplot_pace.png
Binary file modified prob_plots_regress/probplot_pf.png
Binary file modified prob_plots_regress/probplot_stl.png
Binary file modified prob_plots_regress/probplot_total_board.png
Binary file modified prob_plots_regress/probplot_tov.png
Binary file added prob_plots_regress/probplot_trb_pct.png
Empty file modified year_count.yaml
100644 → 100755
Empty file.