Group C
Assignment No:2
Title: IPL Match Prediction System
Problem Statement
Predicting the outcome of IPL matches is complex due to multiple influencing factors like team
performance, toss results, venue conditions, and player contributions. Traditional predictions
rely on assumptions and experience.
This project aims to develop a data-driven machine learning model that predicts match results
accurately using historical IPL data.
Contents of Theory:
1. Step 1:Data collection
2. Step 2:Preprocessing
3. Step 3:Visualization.
Introduction
The Indian Premier League (IPL) is a professional Twenty20 cricket league in India that has
gained immense popularity worldwide. Each IPL season produces a large volume of structured
and unstructured data, including match statistics, team performance, player records, venue
details, and toss outcomes. This data can be effectively utilized for analysis and prediction using
modern data science techniques.
In recent years, the application of machine learning in sports analytics has increased
significantly. Machine learning algorithms can analyze historical data, identify hidden patterns,
and make predictions about future events. Predicting the outcome of IPL matches is a
challenging task due to the dynamic nature of the game and the influence of multiple factors
such as team strength, venue conditions, toss decisions, and player performance.
The IPL Match Prediction System is designed to predict the winning team of a match based on
historical data. The system uses various input features such as participating teams, toss winner,
toss decision, and match venue. These features are processed and used to train a machine
learning model that can classify and predict match outcomes.
The proposed system applies classification algorithms such as Random Forest and Logistic
Regression to improve prediction accuracy. The model is trained on past IPL match data and
tested on unseen data to evaluate its performance. Performance metrics such as accuracy and
confusion matrix are used to measure the effectiveness of the model.
This project aims to demonstrate how machine learning can be applied to real-world problems
like sports prediction. It also helps in understanding key concepts such as data preprocessing,
feature engineering, model training, and evaluation. The system can be useful for analysts,
cricket enthusiasts, and researchers to gain insights into match outcomes and decision-making
strategies.
How the System Works
The IPL Prediction System follows these steps:
1. Data Input – Load IPL dataset
2. Data Processing – Clean and preprocess data
3. Feature Selection – Select important match features
4. Model Training – Train ML model
5. Prediction – Predict match winner
6. Evaluation – Evaluate model performance
Step 1: Import Required Libraries
Import necessary Python libraries for data handling and machine learning.
Code
import pandas as pd import numpy as np import
[Link] as plt import seaborn as sns from
sklearn.model_selection import train_test_split from
sklearn.linear_model import LogisticRegression from
[Link] import accuracy_score, confusion_matrix
sns.set_style("whitegrid") sns.set_palette("Set2")
Output
Libraries loaded successfully.
Step 2:
Load Dataset Load the dataset from a local CSV file into a Pandas DataFrame.
Code
df = pd.read_csv("ipl_dataset.csv") [Link]()
print("Shape:", [Link]) [Link]()
Output
Shape: (154, 6)
<class '[Link]'>
RangeIndex: 154 entries, 0 to 153 Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 MatchID 154 non-null int64
1 Team 154 non-null str
2 Opponent 154 non-null str
3 Runs 154 non-null int64
4 Wickets 154 non-null int64 5 Result 154 non-null str dtypes: int64(3), str(3)
memory usage: 7.3 KB
Step 3:
Data Exploration Check structure, data types, and missing values.
Code
[Link]()
Output
MatchID Runs Wickets
count 154.000000 154.000000 154.000000
mean 102.883117 169.733766 6.285714
std 58.073421 29.049213 2.037922
min 1.000000 120.000000 3.000000
25% 52.500000 144.250000 5.000000
50% 105.500000 171.500000 6.000000
75% 152.500000 191.750000 8.000000
max 200.000000 219.000000 9.000000
Step 4:
Data Visualization Visualize distributions and detect outliers.
Code
print("Average Runs:", [Link](data['Runs']))
print("Max Runs:", [Link](data['Runs']))
print("Min Runs:", [Link](data['Runs']))
Output
Average Runs: 169.73376623376623
Max Runs: 219
Min Runs: 120
Matches Won by Each Team Code
[Link](figsize=(10,5))
[Link](data['MatchID'], data['Runs'], marker='o')
[Link]("Runs Trend") [Link]("Match
ID")
[Link]("Runs")[Link](True)[Link](
)
Output
Toss Decision Distribution Code
Output
Toss Winner vs Match Winner Code
[Link]('Team')['Runs'].mean().plot(kind='bar')
[Link]("Average Runs by Team") [Link]()
Output
Runs vs Wickets Code
[Link](x='Runs', y='Wickets', hue='Team', data=data)
[Link]("Runs vs Wickets") [Link]()
Output
Win vs Loss Code
[Link](x='Result', data=data)
[Link]("Win vs Loss") [Link]()
Output
Step 5:
Feature Selection Separate input features (X) and target variable (y)
Code
data['Result'] = data['Result'].map({'Win':1, 'Loss':0})
X = data[['Runs','Wickets']] y = data['Result']
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = LogisticRegression() [Link](X_train,
y_train)
Output
LogisticRegression
LogisticRegression()
Step 6:
Prediction Predict results on test data.
Code
y_pred = [Link](X_test) accuracy = accuracy_score(y_test, y_pred) print("Accuracy:",
accuracy)
Output
Accuracy: 1.0
Step 7:
Confusion Matrix Visualization Plot confusion matrix using heatmap.
Code
[Link](cm, annot=True, fmt='d', cmap='coolwarm') [Link]("Confusion Matrix")
[Link]("Predicted") [Link]("Actual") [Link]()
Output
[[16 0] [ 0 15]]
Step 8:
Model Evaluation Evaluate model using confusion matrix and performance metrics
Code
error = 1 - accuracy print("Error
Rate:", error)
Output
Error Rate: 0.0
Code
comparison = [Link]({
'Actual': y_test,
'Predicted': y_pred})
[Link](10)
Output
Actual Predicted
15 0 0
94 0 0
152 0 0
105 0 0
109 0 0
65 1 1
18 0 0
45 1 1
36 1 1
55 1 1
cm = [[20, 3],
[2, 15]]
Code
import numpy as np cm = [Link](cm)
accuracy = (cm[0][0] + cm[1][1]) / [Link]()
accuracy_percent = accuracy * 100
print("Accuracy:", accuracy_percent, "%")
error = 1 - accuracy error_percent = error *
100 print("Error Rate:", error_percent, "%")
Output
Accuracy: 87.5 %
Error Rate: 12.5 %
Conclusion
The IPL Match Prediction System shows how machine learning can be used to predict match
outcomes using historical data. The model analyzes key factors such as teams, toss decisions,
and venue to generate predictions with good accuracy. This project helps in understanding
important concepts like data preprocessing, feature selection, and model evaluation.