Update pages/Automatic_Machine_learning_app.py
Browse files
pages/Automatic_Machine_learning_app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import plotly.express as px
|
|
@@ -45,56 +44,57 @@ st.markdown("""
|
|
| 45 |
font-weight: bold;
|
| 46 |
margin: 0;
|
| 47 |
}
|
| 48 |
-
.stTabs [data-baseweb="tab-list"] {
|
| 49 |
-
gap: 10px;
|
| 50 |
-
}
|
| 51 |
-
.stTabs [data-baseweb="tab"] {
|
| 52 |
-
background-color: #F0F3F4;
|
| 53 |
-
border-radius: 5px;
|
| 54 |
-
padding: 10px 20px;
|
| 55 |
-
color: #1A5276;
|
| 56 |
-
}
|
| 57 |
-
.stTabs [data-baseweb="tab"][aria-selected="true"] {
|
| 58 |
-
background-color: #2E86C1;
|
| 59 |
-
color: white;
|
| 60 |
-
}
|
| 61 |
</style>
|
| 62 |
""", unsafe_allow_html=True)
|
| 63 |
|
| 64 |
-
# Data Directory Setup
|
| 65 |
-
data_folder = "cricket_data"
|
| 66 |
-
os.makedirs(data_folder, exist_ok=True)
|
| 67 |
-
|
| 68 |
-
# File Paths
|
| 69 |
-
batting_path = "Teams_batting.csv"
|
| 70 |
-
bowling_path = "team_bowling.csv"
|
| 71 |
-
|
| 72 |
# Load Data
|
|
|
|
|
|
|
|
|
|
| 73 |
try:
|
| 74 |
batting_df = pd.read_csv(batting_path)
|
| 75 |
bowling_df = pd.read_csv(bowling_path)
|
| 76 |
except FileNotFoundError:
|
| 77 |
-
st.error("CSV files not found. Please ensure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
st.stop()
|
| 79 |
|
| 80 |
# Sidebar Configuration
|
| 81 |
with st.sidebar:
|
| 82 |
st.image("https://cdn-icons-png.flaticon.com/512/1099/1099640.png", width=100)
|
| 83 |
st.markdown("### Team Selection")
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
selected_team = st.selectbox("Choose a Team", teams, format_func=lambda x: x.upper())
|
| 86 |
-
|
| 87 |
# Player Selection
|
| 88 |
-
batting_players = batting_df[batting_df[
|
| 89 |
-
bowling_players = bowling_df[bowling_df[
|
| 90 |
players = sorted(set(batting_players).union(bowling_players))
|
| 91 |
selected_player = st.selectbox("Choose a Player", players)
|
| 92 |
|
| 93 |
# Filter Player Data
|
| 94 |
player_batting = batting_df[(batting_df['player_name'] == selected_player) &
|
| 95 |
-
(batting_df[
|
| 96 |
player_bowling = bowling_df[(bowling_df['player_name'] == selected_player) &
|
| 97 |
-
(bowling_df[
|
| 98 |
|
| 99 |
# Main Dashboard
|
| 100 |
st.markdown(f'<div class="main-title">{selected_player}\'s Cricket Analytics</div>', unsafe_allow_html=True)
|
|
@@ -104,10 +104,10 @@ st.markdown('<div class="section-header">Key Performance Metrics</div>', unsafe_
|
|
| 104 |
if not player_batting.empty:
|
| 105 |
col1, col2, col3 = st.columns(3)
|
| 106 |
with col1:
|
| 107 |
-
total_runs = player_batting['
|
| 108 |
st.markdown(f'<div class="metric-card"><h3>Total Runs</h3><p>{total_runs}</p></div>', unsafe_allow_html=True)
|
| 109 |
with col2:
|
| 110 |
-
avg_sr = player_batting['
|
| 111 |
st.markdown(f'<div class="metric-card"><h3>Avg Strike Rate</h3><p>{avg_sr}</p></div>', unsafe_allow_html=True)
|
| 112 |
with col3:
|
| 113 |
matches = len(player_batting)
|
|
@@ -124,17 +124,17 @@ with tab1:
|
|
| 124 |
col1, col2 = st.columns(2)
|
| 125 |
|
| 126 |
with col1:
|
| 127 |
-
fig_runs = px.pie(player_batting, values='
|
| 128 |
title='Runs Distribution by Format',
|
| 129 |
color_discrete_sequence=px.colors.sequential.Blues)
|
| 130 |
fig_runs.update_layout(title_x=0.5)
|
| 131 |
st.plotly_chart(fig_runs, use_container_width=True)
|
| 132 |
|
| 133 |
with col2:
|
| 134 |
-
fig_sr = px.scatter(player_batting, x='
|
| 135 |
-
size='
|
| 136 |
title='Strike Rate Analysis',
|
| 137 |
-
hover_data=['
|
| 138 |
fig_sr.update_layout(title_x=0.5)
|
| 139 |
st.plotly_chart(fig_sr, use_container_width=True)
|
| 140 |
else:
|
|
@@ -146,15 +146,15 @@ with tab2:
|
|
| 146 |
col3, col4 = st.columns(2)
|
| 147 |
|
| 148 |
with col3:
|
| 149 |
-
fig_wickets = px.bar(player_bowling, x='
|
| 150 |
-
color='
|
| 151 |
title='Wickets by Format',
|
| 152 |
color_discrete_sequence=px.colors.sequential.Reds)
|
| 153 |
fig_wickets.update_layout(title_x=0.5)
|
| 154 |
st.plotly_chart(fig_wickets, use_container_width=True)
|
| 155 |
|
| 156 |
with col4:
|
| 157 |
-
fig_eco = px.area(player_bowling, x='
|
| 158 |
title='Economy Rate Trend',
|
| 159 |
color_discrete_sequence=['#2ECC71'])
|
| 160 |
fig_eco.update_layout(title_x=0.5)
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
|
|
|
| 44 |
font-weight: bold;
|
| 45 |
margin: 0;
|
| 46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</style>
|
| 48 |
""", unsafe_allow_html=True)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# Load Data
|
| 51 |
+
batting_path = "Batting_10_Teams_Final.csv"
|
| 52 |
+
bowling_path = "Bowling_10_Teams_Final.csv"
|
| 53 |
+
|
| 54 |
try:
|
| 55 |
batting_df = pd.read_csv(batting_path)
|
| 56 |
bowling_df = pd.read_csv(bowling_path)
|
| 57 |
except FileNotFoundError:
|
| 58 |
+
st.error("CSV files not found. Please ensure the correct files are in the directory.")
|
| 59 |
+
st.stop()
|
| 60 |
+
|
| 61 |
+
# Debugging: Display available columns
|
| 62 |
+
st.write("Batting Data Columns:", batting_df.columns.tolist())
|
| 63 |
+
st.write("Bowling Data Columns:", bowling_df.columns.tolist())
|
| 64 |
+
|
| 65 |
+
# Normalize column names to lowercase
|
| 66 |
+
batting_df.columns = batting_df.columns.str.lower()
|
| 67 |
+
bowling_df.columns = bowling_df.columns.str.lower()
|
| 68 |
+
|
| 69 |
+
# Check if 'country' or 'team' column exists
|
| 70 |
+
if "country" in batting_df.columns:
|
| 71 |
+
team_column = "country"
|
| 72 |
+
elif "team" in batting_df.columns:
|
| 73 |
+
team_column = "team"
|
| 74 |
+
else:
|
| 75 |
+
st.error("Neither 'Country' nor 'Team' column found in the dataset.")
|
| 76 |
st.stop()
|
| 77 |
|
| 78 |
# Sidebar Configuration
|
| 79 |
with st.sidebar:
|
| 80 |
st.image("https://cdn-icons-png.flaticon.com/512/1099/1099640.png", width=100)
|
| 81 |
st.markdown("### Team Selection")
|
| 82 |
+
|
| 83 |
+
# Extract unique teams
|
| 84 |
+
teams = sorted(set(batting_df[team_column].unique()).union(bowling_df[team_column].unique()))
|
| 85 |
selected_team = st.selectbox("Choose a Team", teams, format_func=lambda x: x.upper())
|
| 86 |
+
|
| 87 |
# Player Selection
|
| 88 |
+
batting_players = batting_df[batting_df[team_column] == selected_team]['player_name'].unique()
|
| 89 |
+
bowling_players = bowling_df[bowling_df[team_column] == selected_team]['player_name'].unique()
|
| 90 |
players = sorted(set(batting_players).union(bowling_players))
|
| 91 |
selected_player = st.selectbox("Choose a Player", players)
|
| 92 |
|
| 93 |
# Filter Player Data
|
| 94 |
player_batting = batting_df[(batting_df['player_name'] == selected_player) &
|
| 95 |
+
(batting_df[team_column] == selected_team)]
|
| 96 |
player_bowling = bowling_df[(bowling_df['player_name'] == selected_player) &
|
| 97 |
+
(bowling_df[team_column] == selected_team)]
|
| 98 |
|
| 99 |
# Main Dashboard
|
| 100 |
st.markdown(f'<div class="main-title">{selected_player}\'s Cricket Analytics</div>', unsafe_allow_html=True)
|
|
|
|
| 104 |
if not player_batting.empty:
|
| 105 |
col1, col2, col3 = st.columns(3)
|
| 106 |
with col1:
|
| 107 |
+
total_runs = player_batting['runs'].sum()
|
| 108 |
st.markdown(f'<div class="metric-card"><h3>Total Runs</h3><p>{total_runs}</p></div>', unsafe_allow_html=True)
|
| 109 |
with col2:
|
| 110 |
+
avg_sr = player_batting['sr'].mean().round(2)
|
| 111 |
st.markdown(f'<div class="metric-card"><h3>Avg Strike Rate</h3><p>{avg_sr}</p></div>', unsafe_allow_html=True)
|
| 112 |
with col3:
|
| 113 |
matches = len(player_batting)
|
|
|
|
| 124 |
col1, col2 = st.columns(2)
|
| 125 |
|
| 126 |
with col1:
|
| 127 |
+
fig_runs = px.pie(player_batting, values='runs', names='format',
|
| 128 |
title='Runs Distribution by Format',
|
| 129 |
color_discrete_sequence=px.colors.sequential.Blues)
|
| 130 |
fig_runs.update_layout(title_x=0.5)
|
| 131 |
st.plotly_chart(fig_runs, use_container_width=True)
|
| 132 |
|
| 133 |
with col2:
|
| 134 |
+
fig_sr = px.scatter(player_batting, x='format', y='sr',
|
| 135 |
+
size='runs', color='format',
|
| 136 |
title='Strike Rate Analysis',
|
| 137 |
+
hover_data=['runs'])
|
| 138 |
fig_sr.update_layout(title_x=0.5)
|
| 139 |
st.plotly_chart(fig_sr, use_container_width=True)
|
| 140 |
else:
|
|
|
|
| 146 |
col3, col4 = st.columns(2)
|
| 147 |
|
| 148 |
with col3:
|
| 149 |
+
fig_wickets = px.bar(player_bowling, x='format', y='wickets',
|
| 150 |
+
color='format',
|
| 151 |
title='Wickets by Format',
|
| 152 |
color_discrete_sequence=px.colors.sequential.Reds)
|
| 153 |
fig_wickets.update_layout(title_x=0.5)
|
| 154 |
st.plotly_chart(fig_wickets, use_container_width=True)
|
| 155 |
|
| 156 |
with col4:
|
| 157 |
+
fig_eco = px.area(player_bowling, x='format', y='eco',
|
| 158 |
title='Economy Rate Trend',
|
| 159 |
color_discrete_sequence=['#2ECC71'])
|
| 160 |
fig_eco.update_layout(title_x=0.5)
|