Cricket_playground / pages /Score_predicter.py
zoya23's picture
Update pages/Score_predicter.py
3f4d836 verified
import streamlit as st
import joblib
import numpy as np
# Load the trained model
model = joblib.load('score_prediction_model.pkl')
# App title
st.title("๐Ÿ Team Score Prediction App")
st.markdown("Predict a cricket team's score using batting and bowling stats + team name.")
# Team selection
teams = ['India', 'Australia', 'England', 'Pakistan', 'Afghanistan', 'Sri Lanka',
'South Africa', 'New Zealand', 'Bangladesh', 'West Indies']
team_name = st.selectbox("Select Team", teams)
# Input fields (main page)
st.subheader("๐Ÿ“ฅ Enter Team Performance Stats")
batting_innings = st.slider("Total Batting Innings", 0, 500, 100)
total_fours = st.slider("Total Fours", 0, 1000, 250)
total_sixes = st.slider("Total Sixes", 0, 800, 150)
batting_strike_rate = st.slider("Average Batting Strike Rate", 50.0, 200.0, 95.0)
bowling_wickets = st.slider("Total Bowling Wickets", 0, 500, 100)
bowling_economy = st.slider("Average Bowling Economy", 3.0, 10.0, 5.5)
# Encode team if your model used encoded values (optional - only if model trained that way)
# from sklearn.preprocessing import LabelEncoder
# team_encoder = LabelEncoder()
# team_encoded = team_encoder.transform([team_name])[0]
# Combine features
input_features = np.array([[batting_innings, total_fours, total_sixes,
batting_strike_rate, bowling_wickets, bowling_economy]])
# Predict button
if st.button("๐Ÿ”ฎ Predict Team Score"):
predicted_score = model.predict(input_features)[0]
st.success(f"๐Ÿ Predicted Score for **{team_name}**: **{int(predicted_score)} Runs**")
# Display input summary
st.subheader("๐Ÿ“Š Team Stats You Entered")
st.write({
"Team": team_name,
"Batting Innings": batting_innings,
"Fours": total_fours,
"Sixes": total_sixes,
"Strike Rate": batting_strike_rate,
"Bowling Wickets": bowling_wickets,
"Bowling Economy": bowling_economy
})
# Footer
st.markdown("---")