Update pages/Automatic_Machine_learning_app.py
Browse files
pages/Automatic_Machine_learning_app.py
CHANGED
|
@@ -3,27 +3,16 @@ import pandas as pd
|
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
st.markdown(
|
| 7 |
"""
|
| 8 |
<style>
|
| 9 |
-
.stApp {
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
}
|
| 13 |
-
.stTitle {
|
| 14 |
-
text-align: center;
|
| 15 |
-
color: #374151;
|
| 16 |
-
font-size: 28px;
|
| 17 |
-
font-weight: bold;
|
| 18 |
-
}
|
| 19 |
-
.stSelectbox {
|
| 20 |
-
background-color: white;
|
| 21 |
-
border-radius: 8px;
|
| 22 |
-
padding: 5px;
|
| 23 |
-
}
|
| 24 |
-
.css-1cpxqw2 {
|
| 25 |
-
border-radius: 12px;
|
| 26 |
-
}
|
| 27 |
</style>
|
| 28 |
""",
|
| 29 |
unsafe_allow_html=True
|
|
@@ -31,65 +20,129 @@ st.markdown(
|
|
| 31 |
|
| 32 |
st.markdown("<h1 class='stTitle'>Cricket Icons Dashboard</h1>", unsafe_allow_html=True)
|
| 33 |
|
| 34 |
-
# Load
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
-
st.markdown(f"<h2 class='stTitle'>{
|
| 42 |
-
|
| 43 |
-
st.dataframe(player)
|
| 44 |
|
| 45 |
-
st.markdown(f"<h2 class='stTitle'>{
|
| 46 |
-
|
| 47 |
-
st.dataframe(player1)
|
| 48 |
|
| 49 |
-
# Visualizations
|
| 50 |
st.markdown("<h2 class='stTitle'>Performance Insights</h2>", unsafe_allow_html=True)
|
| 51 |
|
| 52 |
-
# Batting Performance
|
| 53 |
-
if not
|
| 54 |
fig_runs = px.bar(
|
| 55 |
-
|
| 56 |
-
title=f"{
|
| 57 |
color_discrete_sequence=["#1E90FF"]
|
| 58 |
)
|
| 59 |
st.plotly_chart(fig_runs)
|
| 60 |
|
| 61 |
fig_scores = px.bar(
|
| 62 |
-
|
| 63 |
-
title=f"{
|
| 64 |
color_discrete_sequence=["#FFA500"]
|
| 65 |
)
|
| 66 |
st.plotly_chart(fig_scores)
|
| 67 |
|
| 68 |
fig_boundaries = go.Figure()
|
| 69 |
fig_boundaries.add_trace(go.Bar(
|
| 70 |
-
name="Fours", x=
|
| 71 |
marker=dict(color="lime", line=dict(width=2, color="black"))
|
| 72 |
))
|
| 73 |
fig_boundaries.add_trace(go.Bar(
|
| 74 |
-
name="Sixes", x=
|
| 75 |
marker=dict(color="purple", line=dict(width=2, color="black"))
|
| 76 |
))
|
| 77 |
-
fig_boundaries.update_layout(title=f"{
|
| 78 |
st.plotly_chart(fig_boundaries)
|
| 79 |
|
| 80 |
fig_centuries = px.pie(
|
| 81 |
names=["50s", "100s", "200s", "300s", "400s"],
|
| 82 |
-
values=[
|
| 83 |
-
title=f"{
|
| 84 |
hole=0.3, color_discrete_sequence=["#5DADEC", "#FFB6C1", "#FFD700", "#BA55D3", "#FFA07A"]
|
| 85 |
)
|
| 86 |
st.plotly_chart(fig_centuries)
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
fig_wickets = px.bar(
|
| 91 |
-
|
| 92 |
-
title=f"{
|
| 93 |
color_discrete_sequence=["#FF4500"]
|
| 94 |
)
|
| 95 |
st.plotly_chart(fig_wickets)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
|
| 6 |
+
# --- Streamlit Page Styling ---
|
| 7 |
+
st.set_page_config(page_title="Cricket Dashboard", layout="wide")
|
| 8 |
+
|
| 9 |
st.markdown(
|
| 10 |
"""
|
| 11 |
<style>
|
| 12 |
+
.stApp { background: linear-gradient(to right, #eef2ff, #c7d2fe); color: #1f2937; }
|
| 13 |
+
.stTitle { text-align: center; color: #374151; font-size: 28px; font-weight: bold; }
|
| 14 |
+
.stSelectbox { background-color: white; border-radius: 8px; padding: 5px; }
|
| 15 |
+
.css-1cpxqw2 { border-radius: 12px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
</style>
|
| 17 |
""",
|
| 18 |
unsafe_allow_html=True
|
|
|
|
| 20 |
|
| 21 |
st.markdown("<h1 class='stTitle'>Cricket Icons Dashboard</h1>", unsafe_allow_html=True)
|
| 22 |
|
| 23 |
+
# --- Load Datasets ---
|
| 24 |
+
batting_df = pd.read_csv("Teams_batting.csv")
|
| 25 |
+
bowling_df = pd.read_csv("team_bowling.csv")
|
| 26 |
+
|
| 27 |
+
# --- User Selection ---
|
| 28 |
+
teams = batting_df["Team"].unique()
|
| 29 |
+
selected_team = st.selectbox("Select a Team:", teams)
|
| 30 |
+
players = batting_df[batting_df["Team"] == selected_team]["Player"].unique()
|
| 31 |
+
selected_player = st.selectbox("Select a Player:", players)
|
| 32 |
|
| 33 |
+
# --- Filter Player Data ---
|
| 34 |
+
player_batting = batting_df[batting_df["Player"] == selected_player]
|
| 35 |
+
player_bowling = bowling_df[bowling_df["Player"] == selected_player]
|
| 36 |
|
| 37 |
+
st.markdown(f"<h2 class='stTitle'>{selected_player} - Batting Performance</h2>", unsafe_allow_html=True)
|
| 38 |
+
st.dataframe(player_batting)
|
|
|
|
| 39 |
|
| 40 |
+
st.markdown(f"<h2 class='stTitle'>{selected_player} - Bowling Performance</h2>", unsafe_allow_html=True)
|
| 41 |
+
st.dataframe(player_bowling)
|
|
|
|
| 42 |
|
|
|
|
| 43 |
st.markdown("<h2 class='stTitle'>Performance Insights</h2>", unsafe_allow_html=True)
|
| 44 |
|
| 45 |
+
# --- Batting Performance Visualizations ---
|
| 46 |
+
if not player_batting.empty:
|
| 47 |
fig_runs = px.bar(
|
| 48 |
+
player_batting, x="Cricket Matches", y=["Matches", "Innings"],
|
| 49 |
+
title=f"{selected_player} - Matches & Innings", barmode="group", text_auto=True,
|
| 50 |
color_discrete_sequence=["#1E90FF"]
|
| 51 |
)
|
| 52 |
st.plotly_chart(fig_runs)
|
| 53 |
|
| 54 |
fig_scores = px.bar(
|
| 55 |
+
player_batting, x="Cricket Matches", y=["Runs", "Balls"],
|
| 56 |
+
title=f"{selected_player} - Runs & Balls Faced", barmode="group", text_auto=True,
|
| 57 |
color_discrete_sequence=["#FFA500"]
|
| 58 |
)
|
| 59 |
st.plotly_chart(fig_scores)
|
| 60 |
|
| 61 |
fig_boundaries = go.Figure()
|
| 62 |
fig_boundaries.add_trace(go.Bar(
|
| 63 |
+
name="Fours", x=player_batting["Cricket Matches"], y=player_batting["Fours"],
|
| 64 |
marker=dict(color="lime", line=dict(width=2, color="black"))
|
| 65 |
))
|
| 66 |
fig_boundaries.add_trace(go.Bar(
|
| 67 |
+
name="Sixes", x=player_batting["Cricket Matches"], y=player_batting["Sixes"],
|
| 68 |
marker=dict(color="purple", line=dict(width=2, color="black"))
|
| 69 |
))
|
| 70 |
+
fig_boundaries.update_layout(title=f"{selected_player} - Fours & Sixes", barmode="group")
|
| 71 |
st.plotly_chart(fig_boundaries)
|
| 72 |
|
| 73 |
fig_centuries = px.pie(
|
| 74 |
names=["50s", "100s", "200s", "300s", "400s"],
|
| 75 |
+
values=[player_batting["50s"].sum(), player_batting["100s"].sum(), player_batting["200s"].sum(), player_batting["300s"].sum(), player_batting["400s"].sum()],
|
| 76 |
+
title=f"{selected_player} - Milestone Contributions",
|
| 77 |
hole=0.3, color_discrete_sequence=["#5DADEC", "#FFB6C1", "#FFD700", "#BA55D3", "#FFA07A"]
|
| 78 |
)
|
| 79 |
st.plotly_chart(fig_centuries)
|
| 80 |
|
| 81 |
+
# --- Strike Rate Chart ---
|
| 82 |
+
if "SR" in player_batting.columns:
|
| 83 |
+
fig_sr = go.Figure()
|
| 84 |
+
fig_sr.add_trace(
|
| 85 |
+
go.Scatter(
|
| 86 |
+
x=player_batting["Cricket Matches"], y=player_batting["SR"], mode='lines+markers',
|
| 87 |
+
marker=dict(size=10, color='blue', symbol="diamond", line=dict(color='black', width=2)),
|
| 88 |
+
line=dict(width=3, dash="dashdot", color='blue'), name="Strike Rate"
|
| 89 |
+
)
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# Check if there are valid values in 'SR' column
|
| 93 |
+
if not player_batting["SR"].isna().all():
|
| 94 |
+
# Find the index of the maximum strike rate
|
| 95 |
+
max_sr_idx = player_batting["SR"].idxmax()
|
| 96 |
+
|
| 97 |
+
# Ensure the index is valid and within bounds
|
| 98 |
+
if 0 <= max_sr_idx < len(player_batting):
|
| 99 |
+
fig_sr.add_annotation(
|
| 100 |
+
x=player_batting["Cricket Matches"].iloc[max_sr_idx],
|
| 101 |
+
y=player_batting["SR"].iloc[max_sr_idx],
|
| 102 |
+
text=f"🔥 Highest SR: {player_batting['SR'].iloc[max_sr_idx]:.2f}",
|
| 103 |
+
showarrow=True, arrowhead=2, bgcolor="white"
|
| 104 |
+
)
|
| 105 |
+
else:
|
| 106 |
+
st.write("Error: Invalid index for highest strike rate.")
|
| 107 |
+
|
| 108 |
+
fig_sr.update_layout(title="🚀 Strike Rate in Different Matches", xaxis_title="Matches", yaxis_title="Strike Rate")
|
| 109 |
+
st.plotly_chart(fig_sr)
|
| 110 |
+
|
| 111 |
+
# --- Bowling Performance Visualizations ---
|
| 112 |
+
if not player_bowling.empty:
|
| 113 |
fig_wickets = px.bar(
|
| 114 |
+
player_bowling, x="Cricket Matches", y=["Balls", "Maidens", "Wickets", "4w", "5w", "10w"],
|
| 115 |
+
title=f"{selected_player} - Bowling Statistics", barmode="group", text_auto=True,
|
| 116 |
color_discrete_sequence=["#FF4500"]
|
| 117 |
)
|
| 118 |
st.plotly_chart(fig_wickets)
|
| 119 |
+
|
| 120 |
+
# --- Bowling Economy Chart ---
|
| 121 |
+
if "Econ" in player_bowling.columns:
|
| 122 |
+
fig_econ = go.Figure()
|
| 123 |
+
fig_econ.add_trace(
|
| 124 |
+
go.Scatter(
|
| 125 |
+
name="Economy Rate", x=player_bowling["Cricket Matches"], y=player_bowling["Econ"], mode="lines+markers",
|
| 126 |
+
marker=dict(color="red", size=12, symbol="star", line=dict(color="black", width=2)),
|
| 127 |
+
line=dict(width=3, dash="dot", color="red")
|
| 128 |
+
)
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
# Check if there are valid values in 'Econ' column
|
| 132 |
+
if not player_bowling["Econ"].isna().all():
|
| 133 |
+
# Find the index of the minimum economy rate
|
| 134 |
+
min_econ_idx = player_bowling["Econ"].idxmin()
|
| 135 |
+
|
| 136 |
+
# Ensure the index is valid and within bounds
|
| 137 |
+
if 0 <= min_econ_idx < len(player_bowling):
|
| 138 |
+
fig_econ.add_annotation(
|
| 139 |
+
x=player_bowling["Cricket Matches"].iloc[min_econ_idx],
|
| 140 |
+
y=player_bowling["Econ"].iloc[min_econ_idx],
|
| 141 |
+
text=f"🎯 Best Economy: {player_bowling['Econ'].iloc[min_econ_idx]:.2f}",
|
| 142 |
+
showarrow=True, arrowhead=2, bgcolor="white"
|
| 143 |
+
)
|
| 144 |
+
else:
|
| 145 |
+
st.write("Error: Invalid index for best economy rate.")
|
| 146 |
+
|
| 147 |
+
fig_econ.update_layout(title="🎯 Bowling Economy Comparison", xaxis_title="Matches", yaxis_title="Economy Rate")
|
| 148 |
+
st.plotly_chart(fig_econ)
|