Introduction

“Sports has the power to change the world and Inspire people.” - Nelson Mandela.

As we know, there can be no particular reason for people to like sports. There are countless reasons ranging from relaxing and enjoying oneself to feeling the excitement of something unpredictable happening. One such sport is cricket. It is one of the most popular sports in the world, with over 2.5 billion fans. With all the excitement comes the curiosity of trying to predict the winner of a match before it starts. To help with this, we devised the project “IPL Win Prediction.”

Overview

The project “IPL Win prediction” comes under the domain of Sports Analysis. In this project, we try to predict the winner of a cricket match based on data from cricket matches for the past ten years using different machine learning algorithms and also analyze which algorithm is best suited for dealing with this kind of problem. Next, after cleaning and exploring the data, it is divided into two parts, training and testing, In the ratio of 70:30 so the algorithms can be analyzed to find the best among them.

Methods

About the Data set

The data set used in this project is publicly available on Kaggle platform. The two data sets are “matches.csv” which has the data of every team which won and lost in the “Indian Premier League”(IPL) for the years 2008 - 2017. and “deliveries.csv” contaning the play by play data of each match played.

The below table contains description of each variable present in the data.

##           Variable                                     Description         Type
## 1               id                                 ID of the match Quantitative
## 2           season                             Which season of IPL Quantitative
## 3             city            The city in which match is played in  Categorical
## 4             date                               Date of the match  Categorical
## 5            team1                              Name of the team 1  Categorical
## 6            team2                              Name of the team 2  Categorical
## 7      toss_winner              Name of the team that won the toss  Categorical
## 8    toss_decision                 Decision after winning the toss  Categorical
## 9           result                             Result of the match  Categorical
## 10          winner             Name of the team that won the match  Categorical
## 11     win_by_runs      How many runs the team won by if bat first Quantitative
## 12  win_by_wickets How many wickets the team won by if field first Quantitative
## 13 player_of_match                 Player who palyed the best(MVP)  Categorical
## 14           venue     Name of the stadium the match was played in  Categorical
## 15         umpire1             Name of the primary umpire(Referee)  Categorical
## 16         umpire2           Name of the secondary umpire(Referee)  Categorical

Data preprocessing

The libraries used in this project include tidyverse, ggplot, and plotly, skimr, datadictonary. We used the “read.csv()” to import the datasets. Cleaning of the dataset we used the “filter()” function to remove the redundant rows and columns such as umpire3 column, rows with no result, changing the names of the team which describe the same team, and rows containing NA values.

# umpire3 columns only consists of NA values it is redundant information
matches$umpire3 <- NULL
# Removing the rows with no result
matches <- matches %>% filter(!(matches$result == c("no result", "tie")))
# Changing the name of a team because they are same
matches[matches == "Rising Pune Supergiant"] <- "Rising Pune Supergiants"

Data Analysis

The below plot shows the team with most number of wins.

MostToss <- matches %>% filter(toss_winner == winner) %>% count(toss_winner)

MostToss %>% ggplot(aes(x = fct_reorder(toss_winner, n), y = n, color = "black", fill = toss_winner)) + 
  geom_col() +
  coord_flip() +
  labs(title = "Most wins when a team won Toss",
       x = "Teams",
       y = "Number of wins",
       caption = "IPL Dataset of matches from 2008 - 2017") +
  theme_bw() +
  theme(legend.position = "")

This graph shows which team chose to bat first and win the most.

Mostwins_Batfirst <- matches %>% filter((toss_winner == winner) & (toss_decision == "bat")) %>% count(winner)
Mostwins_Batfirst %>% ggplot(aes(x = fct_reorder(winner, n), y = n, color = "black", fill = winner)) + 
  geom_col() +
  coord_flip() +
  labs(title = "Most wins by teams when choose to Bat first",
       x = "Teams",
       y = "Number of wins",
       caption = "IPL Dataset of matches from 2008 - 2017") +
  theme_bw() +
  theme(legend.position = "")

This below graph shows teams who chose to field first and win.

Mostwins_fieldfirst <- matches %>% filter((toss_winner == winner) & (toss_decision == "field")) %>% count(winner)

Mostwins_fieldfirst %>% ggplot(aes(x = fct_reorder(winner, n), y = n, color = "black", fill = winner)) + 
  geom_col() +
  coord_flip() +
  labs(title = "Most wins by teams when choose to Field first",
       x = "Teams",
       y = "Number of wins",
       caption = "IPL Dataset of matches from 2008 - 2017") +
  theme_bw() +
  theme(legend.position = "")

This below graph shows best players in the League.

Most_Player_of_match <- matches%>% count(player_of_match) %>% filter(n > 10)

Most_Player_of_match %>% ggplot(aes(x = fct_reorder(player_of_match, n), y = n, color = "black", fill = player_of_match)) +
  geom_col() +
  theme_bw() + 
  labs(title = " Players who won the most Player_of_Matches(MVP)",
       x = "Name of the Player",
       y = " Number of MVPs",
       caption =  "IPL Dataset of matches from 2008 - 2017") +
  theme(legend.position = " ",
        axis.text.x = element_text(angle = 45,
                                   size = 8,
                                   vjust = 0.70))

This below graph shows distribution of teams winning by more than 50 runs.

MostWin_byruns <- matches %>% filter(win_by_runs > 50) 

MostWin_byruns %>% ggplot(aes(x = win_by_runs, color = "black", fill = winner)) +
  geom_histogram() +
  labs(title = "Distribution of teams winning by more than 50 runs",
       x = "Win by Runs",
       y = "Number of times the team won",
       caption = "IPL Dataset of matches from 2008 - 2017") +
  theme_bw() +
  theme()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

This below graph shows the distribution of teams winning by more than 5 wickets.

MostWin_bywickets <- matches %>% filter(win_by_wickets >= 5)

MostWin_bywickets %>% ggplot(aes(x = win_by_wickets, color = "black", fill = winner)) +
  geom_histogram() +
  labs(title = "Distribution of teams winning by more than 5 wickets",
       x = "Win by wickets",
       y = "Number of times the team won",
       caption = "IPL Dataset of matches from 2008 - 2017") +
  theme_bw() +
  theme()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

This below plot shows most wins when field first

Match1 <- DeliveriesData %>% filter((match_id == 1))

Match1 %>% filter(inning == 1) %>% count(dismissal_kind)
##   dismissal_kind   n
## 1                121
## 2         bowled   1
## 3         caught   3
Match1 %>% filter(inning == 1) %>% count(batsman_runs)
##   batsman_runs  n
## 1            0 32
## 2            1 57
## 3            2  9
## 4            3  1
## 5            4 17
## 6            6  9
data <- Mostwins_fieldfirst

fig <- plot_ly(data, labels = ~winner, values = ~n, type = 'pie')
fig <- fig %>% layout(title = 'Match won when Field first',
         xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
         yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

fig

Models

Work to be done.

Results and Discussion

Work to be done.

Conclusion

Work to be done.

References

Haghighat, M., Rastegari, H., Nourafza, N., Branch, N., & Esfahan, I. (2013). A review of data mining techniques for result prediction in sports. Advances in Computer Science: an International Journal, 2(5), 7-12.

Horvat, T., & Job, J. (2020). The use of machine learning in sport outcome prediction: A review. Wiley Interdisciplinary Reviews: Data Mining and Knowledge Discovery, 10(5), e1380.

Akshitrai. (2020, September 23). ML in everything : IPL winner prediction. Kaggle. Retrieved November 16, 2022, from https://www.kaggle.com/code/akshitrai/ml-in-everything-ipl-winner-prediction