IPL Score Prediction using Deep Learning
Last Updated :
23 Jul, 2025
In today’s world of cricket every run and decision can turn the game around. Using Deep Learning to predict IPL scores during live matches is becoming a game changer. This article shows how advanced algorithms help us to forecast scores with impressive accuracy, giving fans and analysts valuable insights in real time.
Why we using Deep Learning for Score Prediction?
We humans can't easily identify patterns from huge data, deep learning algorithms can do this efficiently. These algorithms learn from how players and teams have performed against each other in the past. Unlike simpler machine learning methods, deep learning can analyze many different factors at once making its score forecasts more reliable and closer to reality.
Now lets implement it step by step:
1. Installing Libraries
We are importing all necessary Python libraries such as NumPy, Pandas, Scikit-learn, Matplotlib, Keras and Seaborn required for data handling, visualization, preprocessing and building deep learning models.
Python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import preprocessing
import keras
import tensorflow as tf
2. Loading the Dataset
The dataset can be downloaded from here. It contains data from 2008 to 2017 and contains features like venue, date, batting and bowling team, names of batsman and bowler, wickets and more. We will load the IPL cricket data from CSV files into pandas DataFrames to explore and prepare for modeling.
Python
ipl = pd.read_csv('ipl_dataset.csv')
ipl.head()
Output:
3. Exploratory Data Analysis
We will do Exploratory Data Analysis (EDA) to analyze how many unique matches have been played at each venue by counting distinct match IDs for every venue. Then, we’ll visualize this data using a horizontal bar chart to see which venues host the most matches.
Python
data = ipl.copy()
matches_per_venue = data[['mid', 'venue']].drop_duplicates()
matches_count = matches_per_venue['venue'].value_counts()
plt.figure(figsize=(12,6))
sns.barplot(x=matches_count.values, y=matches_count.index,palette="rainbow")
plt.title('Number of Matches per Venue')
plt.xlabel('Number of Matches')
plt.ylabel('Venue')
plt.show()
Output:
Matches per stadiumNext we will calculate the maximum runs scored by each batsman by grouping the data by batsman their runs. Then we’ll identify the top 10 batsmen with the highest runs and display this information using a horizontal bar chart.
Python
runs_by_batsman = data.groupby('batsman')['runs'].max().sort_values(ascending=False).head(10)
plt.figure(figsize=(12,6))
sns.barplot(x=runs_by_batsman.values, y=runs_by_batsman.index,palette="pastel")
plt.title('Top 10 Batsmen by Total Runs')
plt.xlabel('Total Runs')
plt.ylabel('Batsman')
plt.show()
Output:
max runs by batsmansAfter that we can do the same for the bowlers, in terms of total wickets.
Python
wickets_by_bowler = data.groupby('bowler')['wickets'].max().sort_values(ascending=False).head(10)
plt.figure(figsize=(12,6))
sns.barplot(x=wickets_by_bowler.values, y=wickets_by_bowler.index, palette="muted")
plt.title('Top 10 Bowlers by Wickets Taken')
plt.xlabel('Total Wickets')
plt.ylabel('Bowler')
plt.show()
Output:
Max wickets my bowlers4. Performing Label Encoding
We will convert categorical text data into numeric labels using Label Encoding because ML models work with numbers.
- LabelEncoder() converts text labels into integers.
- fit_transform() learns encoding and applies it.
- copy() : creates a duplicate of the DataFrame to avoid changing the original data
A dictionary assignment stores each encoder for future use like decoding or consistent transformation
Python
from sklearn.preprocessing import LabelEncoder
cat_cols = ['bat_team', 'bowl_team', 'venue', "batsman", "bowler"]
data_encoded = data.copy()
label_encoders = {}
for col in cat_cols:
le = LabelEncoder()
data_encoded[col] = le.fit_transform(data_encoded[col])
label_encoders[col] = le
We drop date and mid columns because they are identifiers and don’t provide meaningful information for correlation analysis. By removing these irrelevant columns we focus on features that can reveal relationships useful for modeling or insights. Computing and visualizing correlations helps identify which features are related and can guide feature selection.
- drop() : removes specified columns from the DataFrame
- corr() : computes pairwise correlations between numerical features
- sns.heatmap() : creates a colored matrix to visualize correlations with values
- plt.show() : displays the plot on screen
Python
data_corr=data_encoded.drop(columns=["date","mid"],axis=1)
sns.heatmap(data_corr.corr(),annot=True)
plt.show()
Output:
Performing Feature SelectionBased on the heatmap we will drop the columns runs_last_5, wickets_last_5 and non-striker because they show high correlation with other features. Dropping highly correlated columns helps reduce redundancy and prevents multicollinearity which can improve model performance and interpretability.
6. Splitting the Dataset into Training and Testing
We will select relevant features and the target variable then split the data into training and testing sets for model building and evaluation.
- DataFrame indexing (data_encoded[feature_cols]) : selects specified columns as features
- train_test_split() : splits features and target into training and test subsets
- test_size=0.3 : assigns 30% of data for testing
- random_state=42 : ensures reproducible splits by fixing the random seed
Python
feature_cols = ['bat_team', 'bowl_team', 'venue', 'runs', 'wickets', 'overs','striker','batsman','bowler']
X = data_encoded[feature_cols]
y = data_encoded['total']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
7. Performing Feature Scaling
We will perform Min-Max scaling on our input features to ensure all the features are on the same scale. It ensures consistent scale and improves model performance. Scaling will be done on both training and testing data using the scaling parameters.
- MinMaxScaler() scales features to [0,1] range.
- fit_transform() fits scaler on training data and transforms it.
- transform() applies same scaler to test data.
Python
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
8. Building the Neural Network
We will build neural network using TensorFlow and Keras for regression. After building the model we have compiled the model using the Huber Loss because of the robustness of the regression against outliers.
- keras.Sequential() creates a stack of layers.
- Dense layers are fully connected layers.
- activation=relu adds non-linearity.
- Output layer uses linear activation because it’s regression.
- Huber loss combines MSE and MAE advantages to handle outliers better.
- adam optimizer adjusts weights efficiently.
Python
model = keras.Sequential([
keras.layers.Input( shape=(X_train_scaled.shape[1],)),
keras.layers.Dense(512, activation='relu'),
keras.layers.Dense(216, activation='relu'),
keras.layers.Dense(1, activation='linear')
])
huber_loss = tf.keras.losses.Huber(delta=1.0) # You can adjust the 'delta' parameter as needed
model.compile(optimizer='adam', loss=huber_loss)
9. Training the Model
We train the model on the scaled training data for 10 epochs with a batch size of 64, validating on the test set.
- model.fit() trains the model.
- epochs=10 means the model sees the whole data 10 times.
- batch_size=64 updates weights after every 64 samples.
- validation_data evaluates model on test set during training.
Python
model.fit(X_train_scaled, y_train, epochs=10, batch_size=64, validation_data=(X_test_scaled, y_test))
Output:
Model Training We can plot the loss and validation loss of the model.
Python
model_losses = pd.DataFrame(model.history.history)
model_losses.plot()
Output:
Loss VS Validation Loss 10. Evaluating the Model
We predict scores on test data and evaluate model performance using mean absolute error (MAE).
Python
predictions = model.predict(X_test_scaled)
from sklearn.metrics import mean_absolute_error,mean_squared_error
mean_absolute_error(y_test,predictions)
Output:
14.4113130569458
11. Creating an Interactive Widget for Score Prediction
We build an interactive interface using ipywidgets so users can select match details and get a live predicted score.
- widgets.Dropdown() creates dropdown menus.
- widgets.Button() creates a clickable button.
- predict_score() function handles user inputs, encodes and scales them, runs prediction and displays result.
- display() shows widgets in the notebook.
Python
import numpy as np
import ipywidgets as widgets
from IPython.display import display, clear_output
import warnings
warnings.filterwarnings("ignore")
venue = widgets.Dropdown(options=list(label_encoders['venue'].classes_), description='Select Venue:')
venue.style = {'description_width': 'initial'}
batting_team = widgets.Dropdown(options=list(label_encoders['bat_team'].classes_), description='Select Batting Team:')
batting_team.style = {'description_width': 'initial'}
bowling_team = widgets.Dropdown(options=list(label_encoders['bowl_team'].classes_), description='Select Bowling Team:')
bowling_team.style = {'description_width': 'initial'}
striker = widgets.Dropdown(options=list(label_encoders['batsman'].classes_), description='Select Striker:')
striker.style = {'description_width': 'initial'}
bowler = widgets.Dropdown(options=list(label_encoders['bowler'].classes_), description='Select Bowler:')
bowler.style = {'description_width': 'initial'}
runs = widgets.IntText(value=0, description='Runs:', style={'description_width': 'initial'})
wickets = widgets.IntText(value=0, description='Wickets:', style={'description_width': 'initial'})
overs = widgets.FloatText(value=0.0, description='Overs:', style={'description_width': 'initial'})
striker_ind = widgets.IntText(value=0, description='Striker:', style={'description_width': 'initial'}) # Assuming 0 or 1
predict_button = widgets.Button(description="Predict Score")
output = widgets.Output()
def predict_score(b):
with output:
clear_output() # Clear previous output
encoded_venue = label_encoders['venue'].transform([venue.value])[0]
encoded_batting_team = label_encoders['bat_team'].transform([batting_team.value])[0]
encoded_bowling_team = label_encoders['bowl_team'].transform([bowling_team.value])[0]
encoded_striker = label_encoders['batsman'].transform([striker.value])[0]
encoded_bowler = label_encoders['bowler'].transform([bowler.value])[0]
input_features = [
encoded_batting_team,
encoded_bowling_team,
encoded_venue,
runs.value,
wickets.value,
overs.value,
striker_ind.value,
encoded_striker,
encoded_bowler
]
input_array = np.array(input_features).reshape(1, -1)
input_array = scaler.transform(input_array)
predicted_score = model.predict(input_array)
print(f"Predicted Total Runs: {int(predicted_score[0])}")
predict_button.on_click(predict_score)
display(venue, batting_team, bowling_team, striker, bowler,
runs, wickets, overs,
striker_ind,
predict_button, output)
Output:
Interactive Widget for Score PredictionWe have predicted the score of the match between CSK and RCB in Chinnaswamy Cricket Stadium. The predicted score of the match is 152.
You can download the source code from here.
IPL Score Prediction Using Deep Learning
Similar Reads
Deep Learning Tutorial Deep Learning is a subset of Artificial Intelligence (AI) that helps machines to learn from large datasets using multi-layered neural networks. It automatically finds patterns and makes predictions and eliminates the need for manual feature extraction. Deep Learning tutorial covers the basics to adv
5 min read
Deep Learning Basics
Introduction to Deep LearningDeep Learning is transforming the way machines understand, learn and interact with complex data. Deep learning mimics neural networks of the human brain, it enables computers to autonomously uncover patterns and make informed decisions from vast amounts of unstructured data. How Deep Learning Works?
7 min read
Artificial intelligence vs Machine Learning vs Deep LearningNowadays many misconceptions are there related to the words machine learning, deep learning, and artificial intelligence (AI), most people think all these things are the same whenever they hear the word AI, they directly relate that word to machine learning or vice versa, well yes, these things are
4 min read
Deep Learning Examples: Practical Applications in Real LifeDeep learning is a branch of artificial intelligence (AI) that uses algorithms inspired by how the human brain works. It helps computers learn from large amounts of data and make smart decisions. Deep learning is behind many technologies we use every day like voice assistants and medical tools.This
3 min read
Challenges in Deep LearningDeep learning, a branch of artificial intelligence, uses neural networks to analyze and learn from large datasets. It powers advancements in image recognition, natural language processing, and autonomous systems. Despite its impressive capabilities, deep learning is not without its challenges. It in
7 min read
Why Deep Learning is ImportantDeep learning has emerged as one of the most transformative technologies of our time, revolutionizing numerous fields from computer vision to natural language processing. Its significance extends far beyond just improving predictive accuracy; it has reshaped entire industries and opened up new possi
5 min read
Neural Networks Basics
What is a Neural Network?Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns and enable tasks such as pattern recognition and decision-making.In this article, we will explore the fundamental
11 min read
Types of Neural NetworksNeural networks are computational models that mimic the way biological neural networks in the human brain process information. They consist of layers of neurons that transform the input data into meaningful outputs through a series of mathematical operations. In this article, we are going to explore
7 min read
Layers in Artificial Neural Networks (ANN)In Artificial Neural Networks (ANNs), data flows from the input layer to the output layer through one or more hidden layers. Each layer consists of neurons that receive input, process it, and pass the output to the next layer. The layers work together to extract features, transform data, and make pr
4 min read
Activation functions in Neural NetworksWhile building a neural network, one key decision is selecting the Activation Function for both the hidden layer and the output layer. It is a mathematical function applied to the output of a neuron. It introduces non-linearity into the model, allowing the network to learn and represent complex patt
8 min read
Feedforward Neural NetworkFeedforward Neural Network (FNN) is a type of artificial neural network in which information flows in a single direction i.e from the input layer through hidden layers to the output layer without loops or feedback. It is mainly used for pattern recognition tasks like image and speech classification.
6 min read
Backpropagation in Neural NetworkBack Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Deep Learning Models
Deep Learning Frameworks
TensorFlow TutorialTensorFlow is an open-source machine-learning framework developed by Google. It is written in Python, making it accessible and easy to understand. It is designed to build and train machine learning (ML) and deep learning models. It is highly scalable for both research and production.It supports CPUs
2 min read
Keras TutorialKeras high-level neural networks APIs that provide easy and efficient design and training of deep learning models. It is built on top of powerful frameworks like TensorFlow, making it both highly flexible and accessible. Keras has a simple and user-friendly interface, making it ideal for both beginn
3 min read
PyTorch TutorialPyTorch is an open-source deep learning framework designed to simplify the process of building neural networks and machine learning models. With its dynamic computation graph, PyTorch allows developers to modify the networkâs behavior in real-time, making it an excellent choice for both beginners an
7 min read
Caffe : Deep Learning FrameworkCaffe (Convolutional Architecture for Fast Feature Embedding) is an open-source deep learning framework developed by the Berkeley Vision and Learning Center (BVLC) to assist developers in creating, training, testing, and deploying deep neural networks. It provides a valuable medium for enhancing com
8 min read
Apache MXNet: The Scalable and Flexible Deep Learning FrameworkIn the ever-evolving landscape of artificial intelligence and deep learning, selecting the right framework for building and deploying models is crucial for performance, scalability, and ease of development. Apache MXNet, an open-source deep learning framework, stands out by offering flexibility, sca
6 min read
Theano in PythonTheano is a Python library that allows us to evaluate mathematical operations including multi-dimensional arrays efficiently. It is mostly used in building Deep Learning Projects. Theano works way faster on the Graphics Processing Unit (GPU) rather than on the CPU. This article will help you to unde
4 min read
Model Evaluation
Deep Learning Projects