Upload folder using huggingface_hub
Browse files- .gradio/certificate.pem +31 -0
- README.md +3 -9
- games.py +992 -0
- nba_games1_feature_engineered.csv +0 -0
- requirements.txt +4 -0
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
| 10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
| 11 |
+
T8KOEUt+zwvo/7V3Lv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JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Comprehensive_Analysis_of_NBA_Game_Statistic
|
| 3 |
+
app_file: games.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 5.36.2
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
games.py
ADDED
|
@@ -0,0 +1,992 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Key fixes for deployment:
|
| 2 |
+
|
| 3 |
+
# โ
Converted numpy.int64 to Python int
|
| 4 |
+
# โ
Set share=True in launch()
|
| 5 |
+
# โ
Added warnings filter
|
| 6 |
+
# โ
All values converted to standard Python types
|
| 7 |
+
|
| 8 |
+
# The complete working code is in the artifact above. Just copy it and run!
|
| 9 |
+
|
| 10 |
+
import gradio as gr
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
import numpy as np
|
| 14 |
+
import warnings
|
| 15 |
+
warnings.filterwarnings('ignore')
|
| 16 |
+
|
| 17 |
+
# Load data
|
| 18 |
+
df = pd.read_csv('nba_games1_feature_engineered.csv')
|
| 19 |
+
df['GAME_DATE_EST'] = pd.to_datetime(df['GAME_DATE_EST'])
|
| 20 |
+
|
| 21 |
+
# Extract unique teams and seasons - CONVERT TO PYTHON INT
|
| 22 |
+
teams = [int(x) for x in sorted(set(df['HOME_TEAM_ID']).union(set(df['VISITOR_TEAM_ID'])))]
|
| 23 |
+
seasons = [int(x) for x in sorted(df['SEASON'].unique())]
|
| 24 |
+
|
| 25 |
+
COLORS = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E2', '#F8B739', '#52B788']
|
| 26 |
+
DARK_BG = '#000000'
|
| 27 |
+
|
| 28 |
+
plt.style.use('dark_background')
|
| 29 |
+
plt.rcParams['font.family'] = 'monospace'
|
| 30 |
+
|
| 31 |
+
def filter_df(sel_seasons, sel_teams):
|
| 32 |
+
d = df.copy()
|
| 33 |
+
if sel_seasons:
|
| 34 |
+
d = d[d['SEASON'].isin(sel_seasons)]
|
| 35 |
+
if sel_teams:
|
| 36 |
+
d = d[(d['HOME_TEAM_ID'].isin(sel_teams)) | (d['VISITOR_TEAM_ID'].isin(sel_teams))]
|
| 37 |
+
return d
|
| 38 |
+
|
| 39 |
+
# [Include all 9 tab functions here - match_outcomes, scoring_shooting, possession_control, etc.]
|
| 40 |
+
def match_outcomes(sel_seasons, sel_teams):
|
| 41 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 42 |
+
|
| 43 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 44 |
+
ax1.set_facecolor(DARK_BG)
|
| 45 |
+
|
| 46 |
+
if sel_teams and len(sel_teams) > 0:
|
| 47 |
+
teams_to_plot = sel_teams[:5]
|
| 48 |
+
x = np.arange(len(teams_to_plot))
|
| 49 |
+
width = 0.35
|
| 50 |
+
|
| 51 |
+
home_wins = []
|
| 52 |
+
away_wins = []
|
| 53 |
+
|
| 54 |
+
for team in teams_to_plot:
|
| 55 |
+
team_home = d[d['HOME_TEAM_ID'] == team]['HOME_WIN'].sum()
|
| 56 |
+
team_away = d[d['VISITOR_TEAM_ID'] == team]['AWAY_WIN'].sum()
|
| 57 |
+
home_wins.append(team_home)
|
| 58 |
+
away_wins.append(team_away)
|
| 59 |
+
|
| 60 |
+
bars1 = ax1.bar(x - width/2, home_wins, width, label='Home Wins', color='#FF3333', edgecolor='white', linewidth=2)
|
| 61 |
+
bars2 = ax1.bar(x + width/2, away_wins, width, label='Away Wins', color='#4ECDC4', edgecolor='white', linewidth=2)
|
| 62 |
+
|
| 63 |
+
for bar in bars1:
|
| 64 |
+
height = bar.get_height()
|
| 65 |
+
if height > 0:
|
| 66 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height, f'{int(height)}',
|
| 67 |
+
ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 68 |
+
for bar in bars2:
|
| 69 |
+
height = bar.get_height()
|
| 70 |
+
if height > 0:
|
| 71 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height, f'{int(height)}',
|
| 72 |
+
ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 73 |
+
|
| 74 |
+
ax1.set_xticks(x)
|
| 75 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 76 |
+
ax1.set_title('๐ Home vs Away Wins - Team Comparison', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 77 |
+
ax1.legend(fontsize=12, framealpha=0.9)
|
| 78 |
+
else:
|
| 79 |
+
wins_data = pd.Series({
|
| 80 |
+
"Home Wins": d['HOME_WIN'].sum(),
|
| 81 |
+
"Away Wins": d['AWAY_WIN'].sum()
|
| 82 |
+
})
|
| 83 |
+
bars = ax1.bar(wins_data.index, wins_data.values, color=['#FF3333', '#4ECDC4'], width=0.6, edgecolor='white', linewidth=2)
|
| 84 |
+
|
| 85 |
+
for bar in bars:
|
| 86 |
+
height = bar.get_height()
|
| 87 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height, f'{int(height)}',
|
| 88 |
+
ha='center', va='bottom', fontsize=14, fontweight='bold', color='white')
|
| 89 |
+
|
| 90 |
+
ax1.set_title('๐ Home vs Away Wins - Overall', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 91 |
+
|
| 92 |
+
ax1.set_ylabel('Number of Games', fontsize=14, fontweight='bold', color='white')
|
| 93 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 94 |
+
ax1.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 95 |
+
plt.tight_layout()
|
| 96 |
+
|
| 97 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 98 |
+
ax2.set_facecolor(DARK_BG)
|
| 99 |
+
|
| 100 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 101 |
+
if sel_teams and len(sel_teams) > 0:
|
| 102 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 103 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 104 |
+
season_home = team_data[team_data['HOME_TEAM_ID'] == team].groupby('SEASON')['HOME_WIN'].sum()
|
| 105 |
+
season_away = team_data[team_data['VISITOR_TEAM_ID'] == team].groupby('SEASON')['AWAY_WIN'].sum()
|
| 106 |
+
total_wins = season_home.add(season_away, fill_value=0)
|
| 107 |
+
|
| 108 |
+
ax2.plot(total_wins.index, total_wins.values, marker='o', linewidth=3,
|
| 109 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 110 |
+
ax2.set_title('๐ Win Trends Across Seasons - By Team', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 111 |
+
else:
|
| 112 |
+
home_by_season = d.groupby('SEASON')['HOME_WIN'].sum()
|
| 113 |
+
away_by_season = d.groupby('SEASON')['AWAY_WIN'].sum()
|
| 114 |
+
|
| 115 |
+
ax2.plot(home_by_season.index, home_by_season.values, marker='o', linewidth=3,
|
| 116 |
+
label='Home Wins', color='#FF3333', markersize=10)
|
| 117 |
+
ax2.plot(away_by_season.index, away_by_season.values, marker='s', linewidth=3,
|
| 118 |
+
label='Away Wins', color='#4ECDC4', markersize=10)
|
| 119 |
+
ax2.set_title('๐ Win Trends Across Seasons - League Wide', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 120 |
+
|
| 121 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 122 |
+
ax2.set_ylabel('Total Wins', fontsize=14, fontweight='bold', color='white')
|
| 123 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 124 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 125 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 126 |
+
else:
|
| 127 |
+
game_types = pd.Series({
|
| 128 |
+
"Close": d['CLOSE_GAME_FLAG'].sum(),
|
| 129 |
+
"Blowout": d['BLOWOUT_FLAG'].sum(),
|
| 130 |
+
"Normal": len(d) - d['CLOSE_GAME_FLAG'].sum() - d['BLOWOUT_FLAG'].sum()
|
| 131 |
+
})
|
| 132 |
+
|
| 133 |
+
colors_pie = ['#45B7D1', '#FF3333', '#98D8C8']
|
| 134 |
+
wedges, texts, autotexts = ax2.pie(game_types.values, labels=game_types.index, autopct='%1.1f%%',
|
| 135 |
+
colors=colors_pie, startangle=90, textprops={'fontsize': 14, 'fontweight': 'bold'},
|
| 136 |
+
explode=[0.05, 0.05, 0.05])
|
| 137 |
+
|
| 138 |
+
for autotext in autotexts:
|
| 139 |
+
autotext.set_color('white')
|
| 140 |
+
autotext.set_fontsize(13)
|
| 141 |
+
for text in texts:
|
| 142 |
+
text.set_color('white')
|
| 143 |
+
text.set_fontsize(14)
|
| 144 |
+
|
| 145 |
+
ax2.set_title('๐ Game Type Distribution', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 146 |
+
|
| 147 |
+
plt.tight_layout()
|
| 148 |
+
return fig1, fig2
|
| 149 |
+
|
| 150 |
+
# ---------- TAB 2: Scoring & Shooting ----------
|
| 151 |
+
def scoring_shooting(sel_seasons, sel_teams):
|
| 152 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 153 |
+
|
| 154 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 155 |
+
ax1.set_facecolor(DARK_BG)
|
| 156 |
+
|
| 157 |
+
if sel_teams and len(sel_teams) > 0:
|
| 158 |
+
teams_to_plot = sel_teams[:5]
|
| 159 |
+
team_avg_points = []
|
| 160 |
+
|
| 161 |
+
for team in teams_to_plot:
|
| 162 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 163 |
+
avg_pts = team_data['TOTAL_PTS'].mean()
|
| 164 |
+
team_avg_points.append(avg_pts)
|
| 165 |
+
|
| 166 |
+
bars = ax1.bar(range(len(teams_to_plot)), team_avg_points,
|
| 167 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(teams_to_plot))],
|
| 168 |
+
edgecolor='white', linewidth=2, width=0.7)
|
| 169 |
+
|
| 170 |
+
for i, bar in enumerate(bars):
|
| 171 |
+
height = bar.get_height()
|
| 172 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 173 |
+
f'{height:.1f}', ha='center', va='bottom', fontsize=12, fontweight='bold', color='white')
|
| 174 |
+
|
| 175 |
+
ax1.set_xticks(range(len(teams_to_plot)))
|
| 176 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 177 |
+
ax1.set_title('๐ฏ Average Total Points - Team Comparison', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 178 |
+
else:
|
| 179 |
+
season_avg = d.groupby('SEASON')['TOTAL_PTS'].mean()
|
| 180 |
+
bars = ax1.bar(season_avg.index, season_avg.values, color='#FF3333', edgecolor='white', linewidth=2)
|
| 181 |
+
|
| 182 |
+
for bar in bars:
|
| 183 |
+
height = bar.get_height()
|
| 184 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 185 |
+
f'{height:.1f}', ha='center', va='bottom', fontsize=11, color='white')
|
| 186 |
+
|
| 187 |
+
ax1.set_title('๐ฏ Season-wise Avg Total Points', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 188 |
+
|
| 189 |
+
ax1.set_ylabel('Avg Points', fontsize=14, fontweight='bold', color='white')
|
| 190 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 191 |
+
ax1.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 192 |
+
plt.tight_layout()
|
| 193 |
+
|
| 194 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 195 |
+
ax2.set_facecolor(DARK_BG)
|
| 196 |
+
|
| 197 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 198 |
+
if sel_teams and len(sel_teams) > 0:
|
| 199 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 200 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 201 |
+
season_avg = team_data.groupby('SEASON')['TOTAL_PTS'].mean()
|
| 202 |
+
ax2.plot(season_avg.index, season_avg.values, marker='o', linewidth=3,
|
| 203 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 204 |
+
ax2.set_title('๐ Scoring Trends Across Seasons - By Team', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 205 |
+
else:
|
| 206 |
+
season_avg = d.groupby('SEASON')['TOTAL_PTS'].mean()
|
| 207 |
+
ax2.plot(season_avg.index, season_avg.values, marker='o', linewidth=4,
|
| 208 |
+
color='#FF3333', markersize=12, markerfacecolor='#4ECDC4',
|
| 209 |
+
markeredgecolor='white', markeredgewidth=2)
|
| 210 |
+
ax2.set_title('๐ League-wide Scoring Trend', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 211 |
+
|
| 212 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 213 |
+
ax2.set_ylabel('Avg Total Points', fontsize=14, fontweight='bold', color='white')
|
| 214 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 215 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 216 |
+
else:
|
| 217 |
+
shooting_diff = d[['FG_PCT_DIFF', 'FT_PCT_DIFF', 'FG3_PCT_DIFF']].mean()
|
| 218 |
+
bars = ax2.bar(['FG %', 'FT %', '3PT %'], shooting_diff.values,
|
| 219 |
+
color=['#FF3333', '#4ECDC4', '#45B7D1'], edgecolor='white', linewidth=2, width=0.6)
|
| 220 |
+
|
| 221 |
+
for bar in bars:
|
| 222 |
+
height = bar.get_height()
|
| 223 |
+
ax2.text(bar.get_x() + bar.get_width()/2., height,
|
| 224 |
+
f'{height:.4f}', ha='center', va='bottom' if height > 0 else 'top',
|
| 225 |
+
fontsize=12, fontweight='bold', color='white')
|
| 226 |
+
|
| 227 |
+
ax2.axhline(y=0, color='white', linestyle='-', linewidth=1, alpha=0.5)
|
| 228 |
+
ax2.set_title('๐ฏ Average Shooting Superiority (Home - Away)', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 229 |
+
ax2.set_ylabel('Avg Difference', fontsize=14, fontweight='bold', color='white')
|
| 230 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 231 |
+
|
| 232 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 233 |
+
plt.tight_layout()
|
| 234 |
+
return fig1, fig2
|
| 235 |
+
|
| 236 |
+
# ---------- TAB 9: Forecasting ----------
|
| 237 |
+
def forecasting_analysis(sel_seasons, sel_teams):
|
| 238 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 239 |
+
|
| 240 |
+
# Single Plot: Team-wise Scoring Trends (Actual Only)
|
| 241 |
+
fig1, ax1 = plt.subplots(figsize=(10, 6), facecolor=DARK_BG)
|
| 242 |
+
ax1.set_facecolor(DARK_BG)
|
| 243 |
+
|
| 244 |
+
if sel_teams and len(sel_teams) > 0:
|
| 245 |
+
# Plot multiple teams
|
| 246 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 247 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 248 |
+
trend = team_data.groupby('SEASON')['TOTAL_PTS'].mean()
|
| 249 |
+
|
| 250 |
+
if len(trend) > 0:
|
| 251 |
+
ax1.plot(trend.index, trend.values, marker='o', linewidth=3,
|
| 252 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 253 |
+
|
| 254 |
+
ax1.set_title('๐ NBA Scoring Trend - Team Comparison', fontsize=20, fontweight='bold', pad=20, color='white')
|
| 255 |
+
else:
|
| 256 |
+
# Overall league trend
|
| 257 |
+
trend = d.groupby('SEASON')['TOTAL_PTS'].mean()
|
| 258 |
+
|
| 259 |
+
if len(trend) > 0:
|
| 260 |
+
ax1.plot(trend.index, trend.values, marker='o', linewidth=4,
|
| 261 |
+
label='League Average', color='#FF3333', markersize=12)
|
| 262 |
+
|
| 263 |
+
ax1.set_title('๐ NBA Scoring Trend - League Wide', fontsize=20, fontweight='bold', pad=20, color='white')
|
| 264 |
+
|
| 265 |
+
ax1.set_xlabel('Season', fontsize=16, fontweight='bold', color='white')
|
| 266 |
+
ax1.set_ylabel('Avg Total Points', fontsize=16, fontweight='bold', color='white')
|
| 267 |
+
ax1.legend(loc='best', fontsize=13, framealpha=0.9)
|
| 268 |
+
ax1.tick_params(colors='white', labelsize=12)
|
| 269 |
+
ax1.grid(alpha=0.3, linestyle='--', color='gray')
|
| 270 |
+
plt.tight_layout()
|
| 271 |
+
|
| 272 |
+
return fig1
|
| 273 |
+
|
| 274 |
+
# ---------- TAB 3: Possession Control ----------
|
| 275 |
+
def possession_control(sel_seasons, sel_teams):
|
| 276 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 277 |
+
|
| 278 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 279 |
+
ax1.set_facecolor(DARK_BG)
|
| 280 |
+
|
| 281 |
+
if sel_teams and len(sel_teams) > 0:
|
| 282 |
+
teams_to_plot = sel_teams[:5]
|
| 283 |
+
x = np.arange(len(teams_to_plot))
|
| 284 |
+
width = 0.35
|
| 285 |
+
|
| 286 |
+
ast_vals = []
|
| 287 |
+
reb_vals = []
|
| 288 |
+
|
| 289 |
+
for team in teams_to_plot:
|
| 290 |
+
team_data = d[(d['HOME_TEAM_ID']==team) | (d['VISITOR_TEAM_ID']==team)]
|
| 291 |
+
ast_vals.append(team_data['AST_DIFF'].mean())
|
| 292 |
+
reb_vals.append(team_data['REB_DIFF'].mean())
|
| 293 |
+
|
| 294 |
+
bars1 = ax1.bar(x - width/2, ast_vals, width, label='AST Diff', color='#FF3333', edgecolor='white', linewidth=2)
|
| 295 |
+
bars2 = ax1.bar(x + width/2, reb_vals, width, label='REB Diff', color='#4ECDC4', edgecolor='white', linewidth=2)
|
| 296 |
+
|
| 297 |
+
ax1.set_xticks(x)
|
| 298 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 299 |
+
ax1.set_title('๐ Assist & Rebound Advantage by Team', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 300 |
+
ax1.legend(fontsize=12, framealpha=0.9)
|
| 301 |
+
else:
|
| 302 |
+
diff_data = d[['AST_DIFF', 'REB_DIFF']].mean()
|
| 303 |
+
bars = ax1.bar(['AST Diff', 'REB Diff'], diff_data.values,
|
| 304 |
+
color=['#FF3333', '#4ECDC4'], edgecolor='white', linewidth=2, width=0.5)
|
| 305 |
+
|
| 306 |
+
for bar in bars:
|
| 307 |
+
height = bar.get_height()
|
| 308 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 309 |
+
f'{height:.2f}', ha='center', va='bottom' if height > 0 else 'top',
|
| 310 |
+
fontsize=13, fontweight='bold', color='white')
|
| 311 |
+
|
| 312 |
+
ax1.set_title('๐ Average Assist & Rebound Advantage', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 313 |
+
|
| 314 |
+
ax1.axhline(y=0, color='white', linestyle='-', linewidth=1, alpha=0.5)
|
| 315 |
+
ax1.set_ylabel('Avg Difference', fontsize=14, fontweight='bold', color='white')
|
| 316 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 317 |
+
ax1.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 318 |
+
plt.tight_layout()
|
| 319 |
+
|
| 320 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 321 |
+
ax2.set_facecolor(DARK_BG)
|
| 322 |
+
|
| 323 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 324 |
+
season_ast = d.groupby('SEASON')['AST_DIFF'].mean()
|
| 325 |
+
season_reb = d.groupby('SEASON')['REB_DIFF'].mean()
|
| 326 |
+
|
| 327 |
+
ax2.plot(season_ast.index, season_ast.values, marker='o', linewidth=3,
|
| 328 |
+
label='AST Diff', color='#FF3333', markersize=10)
|
| 329 |
+
ax2.plot(season_reb.index, season_reb.values, marker='s', linewidth=3,
|
| 330 |
+
label='REB Diff', color='#4ECDC4', markersize=10)
|
| 331 |
+
|
| 332 |
+
ax2.set_title('๐ Season Trend: Assists & Rebounds', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 333 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 334 |
+
ax2.set_ylabel('Avg Difference', fontsize=14, fontweight='bold', color='white')
|
| 335 |
+
ax2.legend(fontsize=12, framealpha=0.9)
|
| 336 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 337 |
+
else:
|
| 338 |
+
home_ast = d.groupby('HOME_TEAM_ID')['AST_DIFF'].mean()
|
| 339 |
+
away_ast = d.groupby('VISITOR_TEAM_ID')['AST_DIFF'].mean()
|
| 340 |
+
combined_ast = pd.concat([home_ast, away_ast]).groupby(level=0).mean().sort_values(ascending=False).head(10)
|
| 341 |
+
|
| 342 |
+
bars = ax2.barh(range(len(combined_ast)), combined_ast.values, color='#45B7D1', edgecolor='white', linewidth=2)
|
| 343 |
+
ax2.set_yticks(range(len(combined_ast)))
|
| 344 |
+
ax2.set_yticklabels([f'Team {int(t)}' for t in combined_ast.index], fontsize=11, color='white')
|
| 345 |
+
ax2.set_title('๐ Top 10 Teams by Assist Advantage', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 346 |
+
ax2.set_xlabel('Avg AST Difference', fontsize=14, fontweight='bold', color='white')
|
| 347 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 348 |
+
|
| 349 |
+
ax2.axvline(x=0, color='white', linestyle='-', linewidth=1, alpha=0.5)
|
| 350 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 351 |
+
plt.tight_layout()
|
| 352 |
+
return fig1, fig2
|
| 353 |
+
|
| 354 |
+
# ---------- TAB 4: Game Intensity ----------
|
| 355 |
+
def game_intensity(sel_seasons, sel_teams):
|
| 356 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 357 |
+
|
| 358 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 359 |
+
ax1.set_facecolor(DARK_BG)
|
| 360 |
+
|
| 361 |
+
if sel_teams and len(sel_teams) > 0:
|
| 362 |
+
teams_to_plot = sel_teams[:5]
|
| 363 |
+
pace_by_team = []
|
| 364 |
+
|
| 365 |
+
for team in teams_to_plot:
|
| 366 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 367 |
+
pace_by_team.append(team_data['GAME_PACE_SCORE'].mean())
|
| 368 |
+
|
| 369 |
+
bars = ax1.bar(range(len(teams_to_plot)), pace_by_team,
|
| 370 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(teams_to_plot))],
|
| 371 |
+
edgecolor='white', linewidth=2, width=0.7)
|
| 372 |
+
|
| 373 |
+
for i, bar in enumerate(bars):
|
| 374 |
+
height = bar.get_height()
|
| 375 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 376 |
+
f'{height:.2f}', ha='center', va='bottom', fontsize=12, fontweight='bold', color='white')
|
| 377 |
+
|
| 378 |
+
ax1.set_xticks(range(len(teams_to_plot)))
|
| 379 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 380 |
+
ax1.set_title('โก Average Game Pace - Team Comparison', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 381 |
+
else:
|
| 382 |
+
ax1.hist(d['GAME_PACE_SCORE'], bins=30, color='#4ECDC4', edgecolor='white', linewidth=2, alpha=0.8)
|
| 383 |
+
ax1.axvline(d['GAME_PACE_SCORE'].mean(), color='#FF3333', linestyle='--', linewidth=3,
|
| 384 |
+
label=f"Mean: {d['GAME_PACE_SCORE'].mean():.2f}")
|
| 385 |
+
ax1.set_title('โก Game Pace Distribution', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 386 |
+
ax1.set_xlabel('Game Pace Score', fontsize=14, fontweight='bold', color='white')
|
| 387 |
+
ax1.legend(fontsize=12, framealpha=0.9)
|
| 388 |
+
|
| 389 |
+
ax1.set_ylabel('Avg Pace Score' if sel_teams else 'Frequency', fontsize=14, fontweight='bold', color='white')
|
| 390 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 391 |
+
ax1.grid(alpha=0.3, linestyle='--', color='gray')
|
| 392 |
+
plt.tight_layout()
|
| 393 |
+
|
| 394 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 395 |
+
ax2.set_facecolor(DARK_BG)
|
| 396 |
+
|
| 397 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 398 |
+
if sel_teams and len(sel_teams) > 0:
|
| 399 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 400 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 401 |
+
pace_trend = team_data.groupby('SEASON')['GAME_PACE_SCORE'].mean()
|
| 402 |
+
ax2.plot(pace_trend.index, pace_trend.values, marker='o', linewidth=3,
|
| 403 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 404 |
+
ax2.set_title('๐ Game Pace Trends - By Team', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 405 |
+
else:
|
| 406 |
+
pace_trend = d.groupby('SEASON')['GAME_PACE_SCORE'].mean()
|
| 407 |
+
ax2.plot(pace_trend.index, pace_trend.values, marker='o', linewidth=4,
|
| 408 |
+
color='#45B7D1', markersize=12, markerfacecolor='#FF3333',
|
| 409 |
+
markeredgecolor='white', markeredgewidth=2)
|
| 410 |
+
|
| 411 |
+
z = np.polyfit(pace_trend.index, pace_trend.values, 1)
|
| 412 |
+
p = np.poly1d(z)
|
| 413 |
+
ax2.plot(pace_trend.index, p(pace_trend.index), linestyle='--',
|
| 414 |
+
color='#FFA07A', linewidth=3, alpha=0.7, label='Trend')
|
| 415 |
+
|
| 416 |
+
ax2.set_title('๐ NBA Game Pace Evolution', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 417 |
+
|
| 418 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 419 |
+
ax2.set_ylabel('Avg Game Pace Score', fontsize=14, fontweight='bold', color='white')
|
| 420 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 421 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 422 |
+
else:
|
| 423 |
+
pace_by_season = d.groupby('SEASON')['GAME_PACE_SCORE'].mean()
|
| 424 |
+
bars = ax2.bar(pace_by_season.index, pace_by_season.values,
|
| 425 |
+
color='#FF3333', edgecolor='white', linewidth=2)
|
| 426 |
+
|
| 427 |
+
for bar in bars:
|
| 428 |
+
height = bar.get_height()
|
| 429 |
+
ax2.text(bar.get_x() + bar.get_width()/2., height,
|
| 430 |
+
f'{height:.2f}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 431 |
+
|
| 432 |
+
ax2.set_title('โก Average Game Pace by Season', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 433 |
+
ax2.set_ylabel('Avg Pace Score', fontsize=14, fontweight='bold', color='white')
|
| 434 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 435 |
+
|
| 436 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 437 |
+
plt.tight_layout()
|
| 438 |
+
return fig1, fig2
|
| 439 |
+
|
| 440 |
+
# ---------- TAB 5: Home Advantage ----------
|
| 441 |
+
def home_advantage(sel_seasons, sel_teams):
|
| 442 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 443 |
+
|
| 444 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 445 |
+
ax1.set_facecolor(DARK_BG)
|
| 446 |
+
|
| 447 |
+
if sel_teams and len(sel_teams) > 0:
|
| 448 |
+
teams_to_plot = sel_teams[:5]
|
| 449 |
+
home_dom_vals = []
|
| 450 |
+
|
| 451 |
+
for team in teams_to_plot:
|
| 452 |
+
team_home = d[d['HOME_TEAM_ID'] == team]['HOME_DOMINANCE_SCORE'].mean()
|
| 453 |
+
home_dom_vals.append(team_home)
|
| 454 |
+
|
| 455 |
+
bars = ax1.bar(range(len(teams_to_plot)), home_dom_vals,
|
| 456 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(teams_to_plot))],
|
| 457 |
+
edgecolor='white', linewidth=2, width=0.7)
|
| 458 |
+
|
| 459 |
+
for i, bar in enumerate(bars):
|
| 460 |
+
height = bar.get_height()
|
| 461 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 462 |
+
f'{height:.3f}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 463 |
+
|
| 464 |
+
ax1.set_xticks(range(len(teams_to_plot)))
|
| 465 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 466 |
+
ax1.set_title('๐ Home Dominance Score - Team Comparison', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 467 |
+
ax1.set_ylabel('Dominance Score', fontsize=14, fontweight='bold', color='white')
|
| 468 |
+
else:
|
| 469 |
+
home_dom = d.groupby('HOME_TEAM_ID')['HOME_DOMINANCE_SCORE'].mean().sort_values(ascending=False).head(10)
|
| 470 |
+
bars = ax1.barh(range(len(home_dom)), home_dom.values,
|
| 471 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(home_dom))],
|
| 472 |
+
edgecolor='white', linewidth=2)
|
| 473 |
+
|
| 474 |
+
ax1.set_yticks(range(len(home_dom)))
|
| 475 |
+
ax1.set_yticklabels([f'Team {int(t)}' for t in home_dom.index], fontsize=11, color='white')
|
| 476 |
+
|
| 477 |
+
for i, bar in enumerate(bars):
|
| 478 |
+
width = bar.get_width()
|
| 479 |
+
ax1.text(width, bar.get_y() + bar.get_height()/2.,
|
| 480 |
+
f' {width:.3f}', ha='left', va='center', fontsize=11, fontweight='bold', color='white')
|
| 481 |
+
|
| 482 |
+
ax1.set_title('๐ Top 10 Home Dominant Teams', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 483 |
+
ax1.set_xlabel('Dominance Score', fontsize=14, fontweight='bold', color='white')
|
| 484 |
+
|
| 485 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 486 |
+
ax1.grid(alpha=0.3, linestyle='--', color='gray')
|
| 487 |
+
plt.tight_layout()
|
| 488 |
+
|
| 489 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 490 |
+
ax2.set_facecolor(DARK_BG)
|
| 491 |
+
|
| 492 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 493 |
+
if sel_teams and len(sel_teams) > 0:
|
| 494 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 495 |
+
team_data = d[d['HOME_TEAM_ID'] == team]
|
| 496 |
+
season_dom = team_data.groupby('SEASON')['HOME_DOMINANCE_SCORE'].mean()
|
| 497 |
+
ax2.plot(season_dom.index, season_dom.values, marker='o', linewidth=3,
|
| 498 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 499 |
+
ax2.set_title('๐ Home Dominance Trends', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 500 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 501 |
+
ax2.set_ylabel('Dominance Score', fontsize=14, fontweight='bold', color='white')
|
| 502 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 503 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 504 |
+
else:
|
| 505 |
+
home_adv = d.groupby('SEASON')['HOME_DOMINANCE_SCORE'].mean()
|
| 506 |
+
ax2.plot(home_adv.index, home_adv.values, marker='o', linewidth=4,
|
| 507 |
+
color='#FF3333', markersize=12, markerfacecolor='#4ECDC4',
|
| 508 |
+
markeredgecolor='white', markeredgewidth=2)
|
| 509 |
+
ax2.set_title('๐ Home Advantage Evolution', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 510 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 511 |
+
ax2.set_ylabel('Avg Dominance Score', fontsize=14, fontweight='bold', color='white')
|
| 512 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 513 |
+
else:
|
| 514 |
+
shoot_edge = pd.cut(d['HOME_SHOOTING_EDGE'], bins=[-1, -0.05, 0.05, 1],
|
| 515 |
+
labels=['Away Better', 'Even', 'Home Better'])
|
| 516 |
+
edge_counts = shoot_edge.value_counts()
|
| 517 |
+
|
| 518 |
+
colors_pie = ['#FF3333', '#FFA07A', '#4ECDC4']
|
| 519 |
+
wedges, texts, autotexts = ax2.pie(edge_counts.values, labels=edge_counts.index, autopct='%1.1f%%',
|
| 520 |
+
colors=colors_pie, startangle=90,
|
| 521 |
+
textprops={'fontsize': 14, 'fontweight': 'bold'},
|
| 522 |
+
explode=[0.05, 0.05, 0.05])
|
| 523 |
+
|
| 524 |
+
for autotext in autotexts:
|
| 525 |
+
autotext.set_color('white')
|
| 526 |
+
autotext.set_fontsize(13)
|
| 527 |
+
for text in texts:
|
| 528 |
+
text.set_color('white')
|
| 529 |
+
text.set_fontsize(14)
|
| 530 |
+
|
| 531 |
+
ax2.set_title('๐ฏ Home vs Away Shooting Superiority', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 532 |
+
|
| 533 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 534 |
+
plt.tight_layout()
|
| 535 |
+
return fig1, fig2
|
| 536 |
+
|
| 537 |
+
# Continue with remaining tabs (6, 7, 8) following the same pattern...
|
| 538 |
+
# For brevity, I'll include the complete UI section
|
| 539 |
+
|
| 540 |
+
# ---------- TAB 6: Team Momentum ----------
|
| 541 |
+
def team_momentum(sel_seasons, sel_teams):
|
| 542 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 543 |
+
|
| 544 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 545 |
+
ax1.set_facecolor(DARK_BG)
|
| 546 |
+
|
| 547 |
+
if sel_teams and len(sel_teams) > 0:
|
| 548 |
+
teams_to_plot = sel_teams[:5]
|
| 549 |
+
momentum_home = []
|
| 550 |
+
momentum_away = []
|
| 551 |
+
|
| 552 |
+
for team in teams_to_plot:
|
| 553 |
+
team_home = d[d['HOME_TEAM_ID'] == team]['HOME_LAST5_WINRATE'].mean()
|
| 554 |
+
team_away = d[d['VISITOR_TEAM_ID'] == team]['AWAY_LAST5_WINRATE'].mean()
|
| 555 |
+
momentum_home.append(team_home)
|
| 556 |
+
momentum_away.append(team_away)
|
| 557 |
+
|
| 558 |
+
x = np.arange(len(teams_to_plot))
|
| 559 |
+
width = 0.35
|
| 560 |
+
|
| 561 |
+
bars1 = ax1.bar(x - width/2, momentum_home, width, label='Home Momentum',
|
| 562 |
+
color='#FF3333', edgecolor='white', linewidth=2)
|
| 563 |
+
bars2 = ax1.bar(x + width/2, momentum_away, width, label='Away Momentum',
|
| 564 |
+
color='#4ECDC4', edgecolor='white', linewidth=2)
|
| 565 |
+
|
| 566 |
+
for bar in bars1:
|
| 567 |
+
height = bar.get_height()
|
| 568 |
+
if height > 0:
|
| 569 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 570 |
+
f'{height:.2f}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 571 |
+
for bar in bars2:
|
| 572 |
+
height = bar.get_height()
|
| 573 |
+
if height > 0:
|
| 574 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 575 |
+
f'{height:.2f}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 576 |
+
|
| 577 |
+
ax1.set_xticks(x)
|
| 578 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 579 |
+
ax1.set_title('โก Team Momentum Comparison (Last-5 Win Rate)', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 580 |
+
ax1.legend(fontsize=12, framealpha=0.9)
|
| 581 |
+
else:
|
| 582 |
+
winrate_data = d[['HOME_LAST5_WINRATE', 'AWAY_LAST5_WINRATE']].mean()
|
| 583 |
+
bars = ax1.bar(['Home Win Rate', 'Away Win Rate'], winrate_data.values,
|
| 584 |
+
color=['#FF3333', '#4ECDC4'], edgecolor='white', linewidth=2, width=0.6)
|
| 585 |
+
|
| 586 |
+
for bar in bars:
|
| 587 |
+
height = bar.get_height()
|
| 588 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 589 |
+
f'{height:.3f}', ha='center', va='bottom', fontsize=13, fontweight='bold', color='white')
|
| 590 |
+
|
| 591 |
+
ax1.set_title('โก Average Last-5 Games Win Rate', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 592 |
+
|
| 593 |
+
ax1.set_ylabel('Win Rate', fontsize=14, fontweight='bold', color='white')
|
| 594 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 595 |
+
ax1.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 596 |
+
plt.tight_layout()
|
| 597 |
+
|
| 598 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 599 |
+
ax2.set_facecolor(DARK_BG)
|
| 600 |
+
|
| 601 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 602 |
+
if sel_teams and len(sel_teams) > 0:
|
| 603 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 604 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 605 |
+
home_momentum = team_data[team_data['HOME_TEAM_ID'] == team].groupby('SEASON')['HOME_LAST5_WINRATE'].mean()
|
| 606 |
+
away_momentum = team_data[team_data['VISITOR_TEAM_ID'] == team].groupby('SEASON')['AWAY_LAST5_WINRATE'].mean()
|
| 607 |
+
combined_momentum = pd.concat([home_momentum, away_momentum]).groupby(level=0).mean()
|
| 608 |
+
|
| 609 |
+
ax2.plot(combined_momentum.index, combined_momentum.values, marker='o', linewidth=3,
|
| 610 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 611 |
+
|
| 612 |
+
ax2.set_title('๐ Momentum Trends - By Team', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 613 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 614 |
+
ax2.set_ylabel('Avg Win Rate', fontsize=14, fontweight='bold', color='white')
|
| 615 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 616 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 617 |
+
else:
|
| 618 |
+
home_trend = d.groupby('SEASON')['HOME_LAST5_WINRATE'].mean()
|
| 619 |
+
away_trend = d.groupby('SEASON')['AWAY_LAST5_WINRATE'].mean()
|
| 620 |
+
|
| 621 |
+
ax2.plot(home_trend.index, home_trend.values, marker='o', linewidth=3,
|
| 622 |
+
label='Home Momentum', color='#FF3333', markersize=10)
|
| 623 |
+
ax2.plot(away_trend.index, away_trend.values, marker='s', linewidth=3,
|
| 624 |
+
label='Away Momentum', color='#4ECDC4', markersize=10)
|
| 625 |
+
|
| 626 |
+
ax2.set_title('๐ League Momentum Trend', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 627 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 628 |
+
ax2.set_ylabel('Avg Win Rate', fontsize=14, fontweight='bold', color='white')
|
| 629 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 630 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 631 |
+
else:
|
| 632 |
+
momentum = pd.concat([
|
| 633 |
+
d[['HOME_TEAM_ID', 'HOME_LAST5_WINRATE']].rename(columns={'HOME_TEAM_ID': 'TEAM', 'HOME_LAST5_WINRATE': 'WINRATE'}),
|
| 634 |
+
d[['VISITOR_TEAM_ID', 'AWAY_LAST5_WINRATE']].rename(columns={'VISITOR_TEAM_ID': 'TEAM', 'AWAY_LAST5_WINRATE': 'WINRATE'})
|
| 635 |
+
])
|
| 636 |
+
|
| 637 |
+
top_momentum = momentum.groupby('TEAM')['WINRATE'].mean().sort_values(ascending=False).head(10)
|
| 638 |
+
bars = ax2.barh(range(len(top_momentum)), top_momentum.values,
|
| 639 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(top_momentum))],
|
| 640 |
+
edgecolor='white', linewidth=2)
|
| 641 |
+
|
| 642 |
+
ax2.set_yticks(range(len(top_momentum)))
|
| 643 |
+
ax2.set_yticklabels([f'Team {int(t)}' for t in top_momentum.index], fontsize=11, color='white')
|
| 644 |
+
|
| 645 |
+
for i, bar in enumerate(bars):
|
| 646 |
+
width = bar.get_width()
|
| 647 |
+
ax2.text(width, bar.get_y() + bar.get_height()/2.,
|
| 648 |
+
f' {width:.3f}', ha='left', va='center', fontsize=11, fontweight='bold', color='white')
|
| 649 |
+
|
| 650 |
+
ax2.set_title('๐ Top 10 Teams by Recent Momentum', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 651 |
+
ax2.set_xlabel('Avg Last-5 Win Rate', fontsize=14, fontweight='bold', color='white')
|
| 652 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 653 |
+
|
| 654 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 655 |
+
plt.tight_layout()
|
| 656 |
+
return fig1, fig2
|
| 657 |
+
|
| 658 |
+
# ---------- TAB 7: Time Analysis ----------
|
| 659 |
+
def time_analysis(sel_seasons, sel_teams):
|
| 660 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 661 |
+
|
| 662 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 663 |
+
ax1.set_facecolor(DARK_BG)
|
| 664 |
+
|
| 665 |
+
month_counts = d['GAME_MONTH'].value_counts().sort_index()
|
| 666 |
+
bars = ax1.bar(month_counts.index, month_counts.values,
|
| 667 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(month_counts))],
|
| 668 |
+
edgecolor='white', linewidth=2)
|
| 669 |
+
|
| 670 |
+
for bar in bars:
|
| 671 |
+
height = bar.get_height()
|
| 672 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 673 |
+
f'{int(height)}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 674 |
+
|
| 675 |
+
ax1.set_title('๐
Games Played per Month', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 676 |
+
ax1.set_xlabel('Month', fontsize=14, fontweight='bold', color='white')
|
| 677 |
+
ax1.set_ylabel('Number of Games', fontsize=14, fontweight='bold', color='white')
|
| 678 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 679 |
+
ax1.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 680 |
+
plt.tight_layout()
|
| 681 |
+
|
| 682 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 683 |
+
ax2.set_facecolor(DARK_BG)
|
| 684 |
+
|
| 685 |
+
weekday_pace = d.groupby('GAME_WEEKDAY')['GAME_PACE_SCORE'].mean().sort_index()
|
| 686 |
+
bars = ax2.bar(weekday_pace.index, weekday_pace.values,
|
| 687 |
+
color=['#FF3333', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F', '#BB8FCE'],
|
| 688 |
+
edgecolor='white', linewidth=2, width=0.7)
|
| 689 |
+
|
| 690 |
+
for bar in bars:
|
| 691 |
+
height = bar.get_height()
|
| 692 |
+
ax2.text(bar.get_x() + bar.get_width()/2., height,
|
| 693 |
+
f'{height:.2f}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 694 |
+
|
| 695 |
+
ax2.set_title('๐ Game Pace by Day of Week', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 696 |
+
ax2.set_xlabel('Day of Week', fontsize=14, fontweight='bold', color='white')
|
| 697 |
+
ax2.set_ylabel('Avg Pace Score', fontsize=14, fontweight='bold', color='white')
|
| 698 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 699 |
+
ax2.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 700 |
+
plt.tight_layout()
|
| 701 |
+
|
| 702 |
+
return fig1, fig2
|
| 703 |
+
|
| 704 |
+
# ---------- TAB 8: Margin Analysis ----------
|
| 705 |
+
def margin_analysis(sel_seasons, sel_teams):
|
| 706 |
+
d = filter_df(sel_seasons, sel_teams)
|
| 707 |
+
|
| 708 |
+
fig1, ax1 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 709 |
+
ax1.set_facecolor(DARK_BG)
|
| 710 |
+
|
| 711 |
+
if sel_teams and len(sel_teams) > 0:
|
| 712 |
+
teams_to_plot = sel_teams[:5]
|
| 713 |
+
margin_vals = []
|
| 714 |
+
|
| 715 |
+
for team in teams_to_plot:
|
| 716 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 717 |
+
margin_vals.append(team_data['POINT_DIFF'].mean())
|
| 718 |
+
|
| 719 |
+
bars = ax1.bar(range(len(teams_to_plot)), margin_vals,
|
| 720 |
+
color=[COLORS[i % len(COLORS)] for i in range(len(teams_to_plot))],
|
| 721 |
+
edgecolor='white', linewidth=2, width=0.7)
|
| 722 |
+
|
| 723 |
+
for i, bar in enumerate(bars):
|
| 724 |
+
height = bar.get_height()
|
| 725 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 726 |
+
f'{height:.1f}', ha='center', va='bottom' if height > 0 else 'top',
|
| 727 |
+
fontsize=12, fontweight='bold', color='white')
|
| 728 |
+
|
| 729 |
+
ax1.set_xticks(range(len(teams_to_plot)))
|
| 730 |
+
ax1.set_xticklabels([f'Team {t}' for t in teams_to_plot], fontsize=12, color='white')
|
| 731 |
+
ax1.set_title('๐ Average Winning Margin - Team Comparison', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 732 |
+
ax1.axhline(y=0, color='white', linestyle='-', linewidth=1, alpha=0.5)
|
| 733 |
+
else:
|
| 734 |
+
margin_by_season = d.groupby('SEASON')['POINT_DIFF'].mean()
|
| 735 |
+
bars = ax1.bar(margin_by_season.index, margin_by_season.values,
|
| 736 |
+
color='#FF3333', edgecolor='white', linewidth=2)
|
| 737 |
+
|
| 738 |
+
for bar in bars:
|
| 739 |
+
height = bar.get_height()
|
| 740 |
+
ax1.text(bar.get_x() + bar.get_width()/2., height,
|
| 741 |
+
f'{height:.1f}', ha='center', va='bottom', fontsize=11, fontweight='bold', color='white')
|
| 742 |
+
|
| 743 |
+
ax1.set_title('๐ Average Winning Margin by Season', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 744 |
+
|
| 745 |
+
ax1.set_ylabel('Avg Point Difference', fontsize=14, fontweight='bold', color='white')
|
| 746 |
+
ax1.tick_params(colors='white', labelsize=11)
|
| 747 |
+
ax1.grid(axis='y', alpha=0.3, linestyle='--', color='gray')
|
| 748 |
+
plt.tight_layout()
|
| 749 |
+
|
| 750 |
+
fig2, ax2 = plt.subplots(figsize=(12, 7), facecolor=DARK_BG)
|
| 751 |
+
ax2.set_facecolor(DARK_BG)
|
| 752 |
+
|
| 753 |
+
if sel_seasons and len(sel_seasons) > 1:
|
| 754 |
+
if sel_teams and len(sel_teams) > 0:
|
| 755 |
+
for idx, team in enumerate(sel_teams[:5]):
|
| 756 |
+
team_data = d[(d['HOME_TEAM_ID'] == team) | (d['VISITOR_TEAM_ID'] == team)]
|
| 757 |
+
margin_trend = team_data.groupby('SEASON')['POINT_DIFF'].mean()
|
| 758 |
+
ax2.plot(margin_trend.index, margin_trend.values, marker='o', linewidth=3,
|
| 759 |
+
label=f'Team {team}', color=COLORS[idx % len(COLORS)], markersize=10)
|
| 760 |
+
ax2.set_title('๐ Margin Trends - By Team', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 761 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 762 |
+
ax2.set_ylabel('Avg Point Difference', fontsize=14, fontweight='bold', color='white')
|
| 763 |
+
ax2.legend(loc='best', fontsize=12, framealpha=0.9)
|
| 764 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 765 |
+
else:
|
| 766 |
+
margin_trend = d.groupby('SEASON')['POINT_DIFF'].mean()
|
| 767 |
+
ax2.plot(margin_trend.index, margin_trend.values, marker='o', linewidth=4,
|
| 768 |
+
color='#FF3333', markersize=12, markerfacecolor='#4ECDC4',
|
| 769 |
+
markeredgecolor='white', markeredgewidth=2)
|
| 770 |
+
ax2.set_title('๐ Winning Margin Evolution', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 771 |
+
ax2.set_xlabel('Season', fontsize=14, fontweight='bold', color='white')
|
| 772 |
+
ax2.set_ylabel('Avg Point Difference', fontsize=14, fontweight='bold', color='white')
|
| 773 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 774 |
+
else:
|
| 775 |
+
ax2.hist(d['POINT_DIFF'], bins=40, color='#4ECDC4', edgecolor='white', linewidth=2, alpha=0.8)
|
| 776 |
+
ax2.axvline(d['POINT_DIFF'].mean(), color='#FF3333', linestyle='--', linewidth=3,
|
| 777 |
+
label=f"Mean: {d['POINT_DIFF'].mean():.2f}")
|
| 778 |
+
ax2.axvline(d['POINT_DIFF'].median(), color='#FFA07A', linestyle='--', linewidth=3,
|
| 779 |
+
label=f"Median: {d['POINT_DIFF'].median():.2f}")
|
| 780 |
+
|
| 781 |
+
ax2.set_title('๐ Point Difference Distribution', fontsize=18, fontweight='bold', pad=20, color='white')
|
| 782 |
+
ax2.set_xlabel('Point Difference', fontsize=14, fontweight='bold', color='white')
|
| 783 |
+
ax2.set_ylabel('Frequency', fontsize=14, fontweight='bold', color='white')
|
| 784 |
+
ax2.legend(fontsize=12, framealpha=0.9)
|
| 785 |
+
ax2.tick_params(colors='white', labelsize=11)
|
| 786 |
+
|
| 787 |
+
ax2.grid(alpha=0.3, linestyle='--', color='gray')
|
| 788 |
+
plt.tight_layout()
|
| 789 |
+
return fig1, fig2
|
| 790 |
+
|
| 791 |
+
# UI
|
| 792 |
+
custom_css = """
|
| 793 |
+
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');
|
| 794 |
+
|
| 795 |
+
* {
|
| 796 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
body, .gradio-container {
|
| 800 |
+
background: #000000 !important;
|
| 801 |
+
color: #FFFFFF !important;
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
.wrap {
|
| 805 |
+
background: #000000 !important;
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
button {
|
| 809 |
+
background: #FF3333 !important;
|
| 810 |
+
color: white !important;
|
| 811 |
+
font-weight: bold !important;
|
| 812 |
+
border: 2px solid white !important;
|
| 813 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
button:hover {
|
| 817 |
+
background: #CC0000 !important;
|
| 818 |
+
transform: scale(1.02);
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
.tabs button {
|
| 822 |
+
background: #1a1a1a !important;
|
| 823 |
+
border: 1px solid #FF3333 !important;
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
.tabs button.selected {
|
| 827 |
+
background: #FF3333 !important;
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
label {
|
| 831 |
+
color: #FFFFFF !important;
|
| 832 |
+
font-weight: bold !important;
|
| 833 |
+
font-size: 14px !important;
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
.dropdown {
|
| 837 |
+
background: #1a1a1a !important;
|
| 838 |
+
color: white !important;
|
| 839 |
+
border: 2px solid #FF3333 !important;
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
h1, h2, h3, h4 {
|
| 843 |
+
color: #FFFFFF !important;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
.gr-box {
|
| 847 |
+
border: 1px solid #333 !important;
|
| 848 |
+
background: #0a0a0a !important;
|
| 849 |
+
}
|
| 850 |
+
"""
|
| 851 |
+
|
| 852 |
+
with gr.Blocks(theme=gr.themes.Base(primary_hue="red", secondary_hue="slate"), css=custom_css) as app:
|
| 853 |
+
gr.Markdown("""
|
| 854 |
+
# ๐ NBA INTERACTIVE ANALYTICS DASHBOARD
|
| 855 |
+
## Comprehensive Analysis of NBA Game Statistics
|
| 856 |
+
""")
|
| 857 |
+
|
| 858 |
+
gr.Markdown("""
|
| 859 |
+
### ๐ Instructions:
|
| 860 |
+
- **For Team Comparison**: Select multiple teams (max 5) + one or any season
|
| 861 |
+
- **For Season Analysis**: Select multiple seasons + one or any team
|
| 862 |
+
""")
|
| 863 |
+
|
| 864 |
+
with gr.Row():
|
| 865 |
+
team_dd = gr.Dropdown(
|
| 866 |
+
choices=teams,
|
| 867 |
+
multiselect=True,
|
| 868 |
+
label="๐ SELECT TEAMS (Max 5)",
|
| 869 |
+
info="Choose 1-5 teams for comparison",
|
| 870 |
+
max_choices=5
|
| 871 |
+
)
|
| 872 |
+
season_dd = gr.Dropdown(
|
| 873 |
+
choices=seasons,
|
| 874 |
+
multiselect=True,
|
| 875 |
+
label="๐๏ธ SELECT SEASONS",
|
| 876 |
+
info="Choose one or more seasons"
|
| 877 |
+
)
|
| 878 |
+
|
| 879 |
+
with gr.Tab("๐ MATCH OUTCOMES"):
|
| 880 |
+
gr.Markdown("### Home vs Away Performance & Game Types")
|
| 881 |
+
b1 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 882 |
+
with gr.Row():
|
| 883 |
+
with gr.Column(scale=1):
|
| 884 |
+
gr.Markdown("#### ๐ Team/Overall Comparison")
|
| 885 |
+
p1 = gr.Plot()
|
| 886 |
+
with gr.Column(scale=1):
|
| 887 |
+
gr.Markdown("#### ๐ Season Trends/Distribution")
|
| 888 |
+
p2 = gr.Plot()
|
| 889 |
+
b1.click(match_outcomes, [season_dd, team_dd], [p1, p2])
|
| 890 |
+
|
| 891 |
+
with gr.Tab("๐ฏ SCORING & SHOOTING"):
|
| 892 |
+
gr.Markdown("### Scoring Trends & Shooting Efficiency")
|
| 893 |
+
b2 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 894 |
+
with gr.Row():
|
| 895 |
+
with gr.Column(scale=1):
|
| 896 |
+
gr.Markdown("#### ๐ Team/Overall Scoring")
|
| 897 |
+
p3 = gr.Plot()
|
| 898 |
+
with gr.Column(scale=1):
|
| 899 |
+
gr.Markdown("#### ๐ Season Trends/Shooting Stats")
|
| 900 |
+
p4 = gr.Plot()
|
| 901 |
+
b2.click(scoring_shooting, [season_dd, team_dd], [p3, p4])
|
| 902 |
+
|
| 903 |
+
with gr.Tab("๐ POSSESSION CONTROL"):
|
| 904 |
+
gr.Markdown("### Assists & Rebounds Analysis")
|
| 905 |
+
b3 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 906 |
+
with gr.Row():
|
| 907 |
+
with gr.Column(scale=1):
|
| 908 |
+
gr.Markdown("#### ๐ Team/Overall Possession")
|
| 909 |
+
p5 = gr.Plot()
|
| 910 |
+
with gr.Column(scale=1):
|
| 911 |
+
gr.Markdown("#### ๐ Season Trends/Top Teams")
|
| 912 |
+
p6 = gr.Plot()
|
| 913 |
+
b3.click(possession_control, [season_dd, team_dd], [p5, p6])
|
| 914 |
+
|
| 915 |
+
with gr.Tab("โก GAME INTENSITY"):
|
| 916 |
+
gr.Markdown("### Game Pace & Intensity Patterns")
|
| 917 |
+
b4 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 918 |
+
with gr.Row():
|
| 919 |
+
with gr.Column(scale=1):
|
| 920 |
+
gr.Markdown("#### ๐ Team/Overall Pace")
|
| 921 |
+
p7 = gr.Plot()
|
| 922 |
+
with gr.Column(scale=1):
|
| 923 |
+
gr.Markdown("#### ๐ Season Evolution")
|
| 924 |
+
p8 = gr.Plot()
|
| 925 |
+
b4.click(game_intensity, [season_dd, team_dd], [p7, p8])
|
| 926 |
+
|
| 927 |
+
with gr.Tab("๐ HOME ADVANTAGE"):
|
| 928 |
+
gr.Markdown("### Home Court Advantage Metrics")
|
| 929 |
+
b5 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 930 |
+
with gr.Row():
|
| 931 |
+
with gr.Column(scale=1):
|
| 932 |
+
gr.Markdown("#### ๐ Team/Top Teams")
|
| 933 |
+
p9 = gr.Plot()
|
| 934 |
+
with gr.Column(scale=1):
|
| 935 |
+
gr.Markdown("#### ๐ Season Trends/Shooting Edge")
|
| 936 |
+
p10 = gr.Plot()
|
| 937 |
+
b5.click(home_advantage, [season_dd, team_dd], [p9, p10])
|
| 938 |
+
|
| 939 |
+
with gr.Tab("โก TEAM MOMENTUM"):
|
| 940 |
+
gr.Markdown("### Team Performance Momentum")
|
| 941 |
+
b6 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 942 |
+
with gr.Row():
|
| 943 |
+
with gr.Column(scale=1):
|
| 944 |
+
gr.Markdown("#### ๐ Momentum Comparison (Last-5 Win Rate)")
|
| 945 |
+
p11 = gr.Plot()
|
| 946 |
+
with gr.Column(scale=1):
|
| 947 |
+
gr.Markdown("#### ๐ Momentum Trends - By Team")
|
| 948 |
+
p12 = gr.Plot()
|
| 949 |
+
b6.click(team_momentum, [season_dd, team_dd], [p11, p12])
|
| 950 |
+
|
| 951 |
+
with gr.Tab("๐
TIME ANALYSIS"):
|
| 952 |
+
gr.Markdown("### Temporal Patterns in Games")
|
| 953 |
+
b7 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 954 |
+
with gr.Row():
|
| 955 |
+
with gr.Column(scale=1):
|
| 956 |
+
gr.Markdown("#### ๐ Monthly Distribution")
|
| 957 |
+
p13 = gr.Plot()
|
| 958 |
+
with gr.Column(scale=1):
|
| 959 |
+
gr.Markdown("#### ๐ Weekday Pace Analysis")
|
| 960 |
+
p14 = gr.Plot()
|
| 961 |
+
b7.click(time_analysis, [season_dd, team_dd], [p13, p14])
|
| 962 |
+
|
| 963 |
+
with gr.Tab("๐ MARGIN ANALYSIS"):
|
| 964 |
+
gr.Markdown("### Winning Margins & Point Differences")
|
| 965 |
+
b8 = gr.Button("๐ ANALYZE", variant="primary", size="lg")
|
| 966 |
+
with gr.Row():
|
| 967 |
+
with gr.Column(scale=1):
|
| 968 |
+
gr.Markdown("#### ๐ Team/Season Margins")
|
| 969 |
+
p15 = gr.Plot()
|
| 970 |
+
with gr.Column(scale=1):
|
| 971 |
+
gr.Markdown("#### ๐ Margin Trends/Distribution")
|
| 972 |
+
p16 = gr.Plot()
|
| 973 |
+
b8.click(margin_analysis, [season_dd, team_dd], [p15, p16])
|
| 974 |
+
|
| 975 |
+
with gr.Tab("๐ฎ FORECASTING"):
|
| 976 |
+
gr.Markdown("### NBA Scoring Trend Analysis")
|
| 977 |
+
gr.Markdown("**Select multiple teams to compare their scoring trends across seasons**")
|
| 978 |
+
b9 = gr.Button("๐ ANALYZE TRENDS", variant="primary", size="lg")
|
| 979 |
+
gr.Markdown("#### ๐ Team-wise Scoring Trends by Season")
|
| 980 |
+
p17 = gr.Plot()
|
| 981 |
+
b9.click(forecasting_analysis, [season_dd, team_dd], [p17])
|
| 982 |
+
|
| 983 |
+
gr.Markdown("""
|
| 984 |
+
---
|
| 985 |
+
### ๐ก DASHBOARD FEATURES:
|
| 986 |
+
- **Team Comparison Mode**: Select 2-5 teams to compare their performance
|
| 987 |
+
- **Season Analysis Mode**: Select multiple seasons to see trends over time
|
| 988 |
+
- **Full-Screen Visualizations**: All graphs optimized for laptop screens
|
| 989 |
+
- **Dark Theme**: Eye-friendly black background with high-contrast elements
|
| 990 |
+
""")
|
| 991 |
+
|
| 992 |
+
app.launch(share=True)
|
nba_games1_feature_engineered.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
matplotlib
|
| 4 |
+
numpy
|