├── IPL_Score_Predictor.ipynb
├── README.md
├── ipl_data.csv
├── ipl_score_predictor.py
├── requirements.txt
└── streamlit_app
└── ipl_score_predictor.gif
/README.md:
--------------------------------------------------------------------------------
1 | # IPL Score Predictor
2 |
3 | This Streamlit webapp enables user to predict total runs between teams using current runs and wickets.
4 |
5 | **Algorithms used:**
6 |
7 | * Linear Regression
8 | * K-Nearest Neighbor Regressor
9 | * XGBoost Regressor
10 | * RandomForest Regressor
11 | * SVR
12 | * Decision Tree Regressor
13 |
14 | **Hyperparamter Optimization:**
15 |
16 | Used optuna for paramter optimization.
17 |
18 | **Dataset:**
19 |
20 | The dataset comprises of over by over details of matches and runs from 2008 to 2020.
21 |
22 | Dataset Used: ipl_data.csv
23 |
24 | * mid - match id
25 | * date - when matches are played
26 | * venue - place where matches aew played
27 | * bat_team - batting team
28 | * bowl_team - bowling team
29 | * batsman - batsman
30 | * bowler - bowler
31 | * runs - runs scored
32 | * wickets - wickets
33 | * overs - overs - next 3 are based on this
34 | * run_last_5 - runs scored in last 5 overs
35 | * wicket_last_5 - wickets in last 5 overs
36 | * stricker - batsman playing as main 1
37 | * non-striker - batsman playing as runner up - not main 0
38 | * total - total score (target variable)
39 |
40 | **Streamlit App:**
41 |
42 | 
43 |
--------------------------------------------------------------------------------
/ipl_score_predictor.py:
--------------------------------------------------------------------------------
1 | #import the libraries
2 |
3 | import math
4 | import numpy as np
5 | import pickle
6 | import streamlit as st
7 |
8 | #SET PAGE WIDE
9 | st.set_page_config(page_title='IPL_Score_Predictor',layout="centered")
10 |
11 | #Get the ML model
12 |
13 | filename='ml_model.pkl'
14 | model = pickle.load(open(filename,'rb'))
15 |
16 | #Title of the page with CSS
17 |
18 | st.markdown("
IPL Score Predictor 2022
", unsafe_allow_html=True)
19 |
20 | #Add background image
21 |
22 | st.markdown(
23 | f"""
24 |
31 | """,
32 | unsafe_allow_html=True
33 | )
34 |
35 | #Add description
36 |
37 | with st.expander("Description"):
38 | st.info("""A Simple ML Model to predict IPL Scores between teams in an ongoing match. To make sure the model results accurate score and some reliability the minimum no. of current overs considered is greater than 5 overs.
39 |
40 | """)
41 |
42 | # SELECT THE BATTING TEAM
43 |
44 |
45 | batting_team= st.selectbox('Select the Batting Team ',('Chennai Super Kings', 'Delhi Daredevils', 'Kings XI Punjab','Kolkata Knight Riders','Mumbai Indians','Rajasthan Royals','Royal Challengers Bangalore','Sunrisers Hyderabad'))
46 |
47 | prediction_array = []
48 | # Batting Team
49 | if batting_team == 'Chennai Super Kings':
50 | prediction_array = prediction_array + [1,0,0,0,0,0,0,0]
51 | elif batting_team == 'Delhi Daredevils':
52 | prediction_array = prediction_array + [0,1,0,0,0,0,0,0]
53 | elif batting_team == 'Kings XI Punjab':
54 | prediction_array = prediction_array + [0,0,1,0,0,0,0,0]
55 | elif batting_team == 'Kolkata Knight Riders':
56 | prediction_array = prediction_array + [0,0,0,1,0,0,0,0]
57 | elif batting_team == 'Mumbai Indians':
58 | prediction_array = prediction_array + [0,0,0,0,1,0,0,0]
59 | elif batting_team == 'Rajasthan Royals':
60 | prediction_array = prediction_array + [0,0,0,0,0,1,0,0]
61 | elif batting_team == 'Royal Challengers Bangalore':
62 | prediction_array = prediction_array + [0,0,0,0,0,0,1,0]
63 | elif batting_team == 'Sunrisers Hyderabad':
64 | prediction_array = prediction_array + [0,0,0,0,0,0,0,1]
65 |
66 |
67 |
68 |
69 | #SELECT BOWLING TEAM
70 |
71 | bowling_team = st.selectbox('Select the Bowling Team ',('Chennai Super Kings', 'Delhi Daredevils', 'Kings XI Punjab','Kolkata Knight Riders','Mumbai Indians','Rajasthan Royals','Royal Challengers Bangalore','Sunrisers Hyderabad'))
72 | if bowling_team==batting_team:
73 | st.error('Bowling and Batting teams should be different')
74 | # Bowling Team
75 | if bowling_team == 'Chennai Super Kings':
76 | prediction_array = prediction_array + [1,0,0,0,0,0,0,0]
77 | elif bowling_team == 'Delhi Daredevils':
78 | prediction_array = prediction_array + [0,1,0,0,0,0,0,0]
79 | elif bowling_team == 'Kings XI Punjab':
80 | prediction_array = prediction_array + [0,0,1,0,0,0,0,0]
81 | elif bowling_team == 'Kolkata Knight Riders':
82 | prediction_array = prediction_array + [0,0,0,1,0,0,0,0]
83 | elif bowling_team == 'Mumbai Indians':
84 | prediction_array = prediction_array + [0,0,0,0,1,0,0,0]
85 | elif bowling_team == 'Rajasthan Royals':
86 | prediction_array = prediction_array + [0,0,0,0,0,1,0,0]
87 | elif bowling_team == 'Royal Challengers Bangalore':
88 | prediction_array = prediction_array + [0,0,0,0,0,0,1,0]
89 | elif bowling_team == 'Sunrisers Hyderabad':
90 | prediction_array = prediction_array + [0,0,0,0,0,0,0,1]
91 |
92 |
93 | col1, col2 = st.columns(2)
94 |
95 | #Enter the Current Ongoing Over
96 | with col1:
97 | overs = st.number_input('Enter the Current Over',min_value=5.1,max_value=19.5,value=5.1,step=0.1)
98 | if overs-math.floor(overs)>0.5:
99 | st.error('Please enter valid over input as one over only contains 6 balls')
100 | with col2:
101 | #Enter Current Run
102 | runs = st.number_input('Enter Current runs',min_value=0,max_value=354,step=1,format='%i')
103 |
104 |
105 | #Wickets Taken till now
106 | wickets =st.slider('Enter Wickets fallen till now',0,9)
107 | wickets=int(wickets)
108 |
109 | col3, col4 = st.columns(2)
110 |
111 | with col3:
112 | #Runs in last 5 over
113 | runs_in_prev_5 = st.number_input('Runs scored in the last 5 overs',min_value=0,max_value=runs,step=1,format='%i')
114 |
115 | with col4:
116 | #Wickets in last 5 over
117 | wickets_in_prev_5 = st.number_input('Wickets taken in the last 5 overs',min_value=0,max_value=wickets,step=1,format='%i')
118 |
119 | #Get all the data for predicting
120 |
121 | prediction_array = prediction_array + [runs, wickets, overs, runs_in_prev_5,wickets_in_prev_5]
122 | prediction_array = np.array([prediction_array])
123 | predict = model.predict(prediction_array)
124 |
125 |
126 | if st.button('Predict Score'):
127 | #Call the ML Model
128 | my_prediction = int(round(predict[0]))
129 |
130 | #Display the predicted Score Range
131 | x=f'PREDICTED MATCH SCORE : {my_prediction-5} to {my_prediction+5}'
132 | st.success(x)
133 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | numpy==1.23.5
2 | streamlit==1.16.0
3 | matplotlib==3.6.3
4 | pandas==1.5.2
5 | scikit_learn==1.2.0
6 | seaborn==0.12.2
7 | xgboost==1.7.3
8 |
--------------------------------------------------------------------------------
/streamlit_app/ipl_score_predictor.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zep-analytics/IPLScorePredictor/cd7f589779bbfcae5c38eb1ed61e55cbd27421d0/streamlit_app/ipl_score_predictor.gif
--------------------------------------------------------------------------------