You are on page 1of 46

11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Import libraries
In [83]: # Importing necessary libraries for data analysis and visualization
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

In [84]: # Read the data from "World_cup_2023.csv" into the 'World_cup' DataFrame
World_cup = pd.read_csv("World_cup_2023.csv")

# Read the data from "results.csv" into the 'results' DataFrame


results = pd.read_csv("results.csv")

In [85]: # Display the first few rows of the World_cup DataFrame.


World_cup

Out[85]: Team_name Team_ranking Titles Win_percentage_ODI WC_matches WC_match_won Win_perc

0 Australia 1 5 60.73 94 69

1 Pakistan 2 1 52.78 79 45

2 India 3 2 52.38 84 53

New
3 4 0 45.89 89 54
Zealand

4 England 5 1 50.32 83 48

5 South Africa 6 0 61.00 64 38

6 Bangladesh 7 0 36.65 40 14

7 Afghanistan 8 0 49.65 15 1

8 Sri Lanka 9 1 45.74 80 38

9 Netherlands 10 0 34.21 20 2

No.of titles won by each teams


In [86]: # Set the figure size using sns.set
sns.set(rc={'figure.figsize':(20, 5)})

# Create a bar plot using sns.barplot to visualize team titles


sns.barplot(x='Team_name', y='Titles', data=World_cup)

# Display the plot


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 1/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Win percentage in ODI by each team


In [87]: # Set the figure size for the bar plot using Seaborn
sns.set(rc={'figure.figsize':(20, 5)})

# Create a bar plot using Seaborn


sns.barplot(x='Team_name', y='Win_percentage_ODI', data=World_cup)

# Display the plot


plt.show()

No.of matches won in world cup by each team


In [88]: # Set the figure size for the bar plot using Seaborn
sns.set(rc={'figure.figsize':(20, 5)})

# Create a bar plot using Seaborn


sns.barplot(x='Team_name', y='WC_match_won', data=World_cup)

# Display the plot


plt.show()

Recent ICC ODI rating

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 2/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [89]: # Set the figure size for the bar plot using Seaborn
sns.set(rc={'figure.figsize':(20, 5)})

# Create a bar plot using Seaborn to display recent ratings of teams


sns.barplot(x='Team_name', y='Rating', data=World_cup)

# Display the plot


plt.show()

In [90]: # Displaying the first few rows of the results DataFrame.


results.head()

Out[90]: Date Team_1 Team_2 Winner Margin Ground

Shere Bangla National


0 17/04/2015 Bangladesh Pakistan Bangladesh won by 79 runs
Stadium

won by 7 Shere Bangla National


1 19/04/2015 Bangladesh Pakistan Bangladesh
wickets Stadium

won by 8 Shere Bangla National


2 22/04/2015 Bangladesh Pakistan Bangladesh
wickets Stadium

3 08/05/2015 Ireland England No result No result The Village

4 26/05/2015 Pakistan Zimbabwe Pakistan won by 41 runs Gaddafi Stadium

In [91]: # Removing rows with 'Match abandoned' and 'No result' from the 'results' DataFrame
results.drop(results[(results['Winner'] == 'Match abandoned' )].index, inplace=True
results.drop(results[(results['Winner'] == 'No result' )].index, inplace=True)

Stats of top five teams in the ODI world cup 2023

Stats of Indian team


In [92]: # Filter the 'results' DataFrame to include rows where India played either as Team_
df = results[(results['Team_1'] == 'India') | (results['Team_2'] == 'India')]

# Create a new DataFrame 'India' containing all rows from the filtered DataFrame
India = df.iloc[:]

# Display the first few rows of the 'India' DataFrame


India.head()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 3/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[92]: Date Team_1 Team_2 Winner Margin Ground

11 18/06/2015 Bangladesh India Bangladesh won by 79 runs Shere Bangla National Stadium

13 21/06/2015 Bangladesh India Bangladesh won by 6 wickets Shere Bangla National Stadium

14 24/06/2015 Bangladesh India India won by 77 runs Shere Bangla National Stadium

16 10/07/2015 Zimbabwe India India won by 4 runs Harare Sports Club

19 12/07/2015 Zimbabwe India India won by 62 runs Harare Sports Club

In [93]: # Filtering the 'India' dataframe to create a new dataframe 'India_win' containing
India_win = India[India['Winner']=='India']

In [94]: India_win

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 4/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[94]: Date Team_1 Team_2 Winner Margin Ground

won by 77
14 24/06/2015 Bangladesh India India Shere Bangla National Stadium
runs

won by 4
16 10/07/2015 Zimbabwe India India Harare Sports Club
runs

won by 62
19 12/07/2015 Zimbabwe India India Harare Sports Club
runs

won by 83
20 14/07/2015 Zimbabwe India India Harare Sports Club
runs

won by 6
73 23/01/2016 Australia India India Sydney Cricket Ground
wickets

won by 9
87 11/06/2016 Zimbabwe India India Harare Sports Club
wickets

won by 8
89 13/06/2016 Zimbabwe India India Harare Sports Club
wickets

won by 10
91 15/06/2016 Zimbabwe India India Harare Sports Club
wickets

New won by 7 Punjab Cricket Association IS


141 23/10/2016 India India
Zealand wickets Bindra Stadium

won by 6
288 01/02/2018 South Africa India India Kingsmead
wickets

won by 9
289 04/02/2018 South Africa India India SuperSport Park
wickets

won by 124
290 07/02/2018 South Africa India India Newlands
runs

won by 73
295 13/02/2018 South Africa India India St George's Park
runs

won by 8
297 16/02/2018 South Africa India India SuperSport Park
wickets

won by 8
314 12/07/2018 England India India Trent Bridge
wickets

won by 26 Dubai International Cricket


338 18/09/2018 Hong Kong India India
runs Stadium

won by 7 Dubai International Cricket


341 21/09/2018 Bangladesh India India
wickets Stadium

won by 3 Dubai International Cricket


347 28/09/2018 Bangladesh India India
wickets Stadium

West won by 9
363 01/11/2018 India India Greenfield International Stadium
Indies wickets

New won by 35
387 03/02/2019 India India Sky Stadium
Zealand runs

won by 36
448 09/06/2019 Australia India India Kennington Oval
runs

won by 11
464 22/06/2019 Afghanistan India India The Rose Bowl
runs

won by 28
476 02/07/2019 Bangladesh India India Edgbaston
runs

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 5/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Date Team_1 Team_2 Winner Margin Ground

won by 59
488 11/08/2019 West Indies India India Queen's Park Oval
runs

won by 6
489 14/08/2019 West Indies India India Queen's Park Oval
wickets

West won by 107 Dr YS Rajasekhara Reddy Cricket


497 18/12/2019 India India
Indies runs Stadium

West won by 4
498 22/12/2019 India India Barabati Stadium
Indies wickets

won by 36 Saurashtra Cricket Association


499 17/01/2020 India Australia India
runs Stadium

won by 7
500 19/01/2020 India Australia India M Chinnaswamy Stadium
wickets

won by 13
530 02/12/2020 Australia India India Manuka Oval
runs

won by 66 Maharashtra Cricket Association


540 23/03/2021 India England India
runs Stadium

won by 7 Maharashtra Cricket Association


544 28/03/2021 India England India
runs Stadium

won by 7
566 18/07/2021 Sri Lanka India India R Premadasa Stadium
wickets

won by 3
569 20/07/2021 Sri Lanka India India R Premadasa Stadium
wickets

West won by 6
588 06/02/2022 India India Narendra Modi Stadium
Indies wickets

West won by 44
589 09/02/2022 India India Narendra Modi Stadium
Indies runs

West won by 96
590 11/02/2022 India India Narendra Modi Stadium
Indies runs

won by 10
621 12/07/2022 England India India Kennington Oval
wickets

won by 5
627 17/07/2022 England India India Old Trafford
wickets

won by 3
629 22/07/2022 West Indies India India Queen's Park Oval
runs

won by 2
631 24/07/2022 West Indies India India Queen's Park Oval
wickets

won by 119
633 27/07/2022 West Indies India India Queen's Park Oval
runs

won by 10
640 18/08/2022 Zimbabwe India India Harare Sports Club
wickets

won by 5
643 20/08/2022 Zimbabwe India India Harare Sports Club
wickets

won by 13
646 22/08/2022 Zimbabwe India India Harare Sports Club
runs

South won by 7 JSCA International Stadium


654 09/10/2022 India India
Africa wickets Complex

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 6/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Date Team_1 Team_2 Winner Margin Ground

South won by 7
655 11/10/2022 India India Arun Jaitley Stadium
Africa wickets

won by 227 Zahur Ahmed Chowdhury


667 10/12/2022 Bangladesh India India
runs Stadium

won by 67
669 10/01/2023 India Sri Lanka India Barsapara Cricket Stadium
runs

won by 4
671 12/01/2023 India Sri Lanka India Eden Gardens
wickets

won by 317
672 15/01/2023 India Sri Lanka India Greenfield International Stadium
runs

New won by 12 Rajiv Gandhi International


673 18/01/2023 India India
Zealand runs Stadium

New won by 8 Shaheed Veer Narayan Sing


674 21/01/2023 India India
Zealand wickets International Stadium

New won by 90
675 24/01/2023 India India Holkar Cricket Stadium
Zealand runs

won by 5
683 17/03/2023 India Australia India Wankhede Stadium
wickets

No.of wins in ODIs against other teams


In [95]: # Exclude Team India's name
excluded_value = 'India'

# Filtering out rows with the excluded value


filtered_df = India_win[India_win['Team_2'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()

# Print the value counts


print(value_counts)

West Indies 6
New Zealand 4
Australia 3
Sri Lanka 3
England 2
South Africa 2
Name: Team_2, dtype: int64

In [96]: # Exclude Team India's name


excluded_value = 'India'

# Filtering out rows with the excluded value


filtered_df = India_win[India_win['Team_1'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_1'].value_counts()

# Print the value counts


print(value_counts)

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 7/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
Zimbabwe 5
South Africa 5
West Indies 5
Bangladesh 4
Zimbabwe 4
Australia 2
Sri Lanka 2
England 2
England 1
Hong Kong 1
New Zealand 1
Afghanistan 1
Australia 1
Bangladesh 1
Name: Team_1, dtype: int64

Displaying Team India's wins against other teams


using bar graph
In [97]: # Exclude Team India
exclude = 'India'

# Filter out the opponent to exclude from the data


filtered_data = India_win[India_win['Team_2'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by India.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_2'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

In [98]: # Exclude Team India


exclude = 'India'

# Filter out the opponent to exclude from the data


filtered_data = India_win[India_win['Team_1'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by India.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_1'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 8/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Win Percentage of India Against Each Team


In [99]: # Number of wins against each team
# Out of the 1032 ODI matches played by India, number of matches won against the fo
team_win_counts = {
'Australia': 54,
'New Zealand': 58,
'South Africa ': 37,
'Pakistan': 55,
'Sri Lanka': 93,
'Bangladesh': 30,
'England': 57,
'Netherlands': 2,
'Afghanistan': 3
}

# Total matches played is calculated


total_matches = sum(team_win_counts.values())

# India's win percentages against each team is calculated


win_percentages = {team: (wins / total_matches) * 100 for team, wins in team_win_co

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of India Against Each Team')

# Display the pie chart


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 9/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Win Percentage of India in the ODI world cup


In [100… # Number of wins against each team in the ODI world cup
# Out of the 84 ODI matches played by India in the ODI world cup, number of matches
team_win_counts_wc_ind = {
'Australia': 4,
'New Zealand': 3,
'South Africa ': 2,
'Pakistan': 7,
'Sri Lanka': 5,
'Bangladesh': 3,
'England': 3,
'Netherlands': 2,
'Afghanistan': 2
}

# Total matches played is calculated


total_matches_wc_ind = sum(team_win_counts_wc_ind.values())

# India's win percentages against each team is calculated


win_percentages_wc_ind = {team: (wins / total_matches_wc_ind) * 100 for team, wins

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_ind.values(), labels=win_percentages_wc_ind.keys(), auto

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of India in the ODI world cup')

# Display the pie chart


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 10/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Stats of Australian team


In [101… # Filter the 'results' DataFrame to include rows where Australia played either as T
df1 = results[(results['Team_1'] == 'Australia') | (results['Team_2'] == 'Australia

# Create a new DataFrame 'Australia' containing all rows from the filtered DataFram
Australia = df1.iloc[:]

# Display the first few rows of the 'Australia' DataFrame


Australia.head()

Out[101]: Date Team_1 Team_2 Winner Margin Ground

32 27/08/2015 Ireland Australia Australia won by 23 runs Civil Service Cricket Club

33 03/09/2015 England Australia Australia won by 59 runs The Rose Bowl

34 05/09/2015 England Australia Australia won by 64 runs Lord's

35 08/09/2015 England Australia England won by 93 runs Old Trafford

36 11/09/2015 England Australia England won by 3 wickets Headingley

In [102… # Filtering the 'Australia' dataframe to create a new dataframe 'Australia_win' con
Australia_win = Australia[Australia['Winner']=='Australia']

In [103… Australia_win

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 11/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[103]: Date Team_1 Team_2 Winner Margin Ground

won by 8
37 12/09/2015 England Australia Australia Old Trafford
wickets

New won by 4
79 06/02/2016 Australia Australia Sky Stadium
Zealand wickets

won by 6
85 05/06/2016 West Indies Australia Australia Providence Stadium
wickets

South won by 36
88 11/06/2016 Australia Australia Warner Park
Africa runs

won by 6
97 21/06/2016 West Indies Australia Australia Kensington Oval
wickets

won by 58
101 26/06/2016 West Indies Australia Australia Kensington Oval
runs

won by 3
113 21/08/2016 Sri Lanka Australia Australia R Premadasa Stadium
wickets

won by 2 Rangiri Dambulla International


117 28/08/2016 Sri Lanka Australia Australia
wickets Stadium

won by 6 Rangiri Dambulla International


119 31/08/2016 Sri Lanka Australia Australia
wickets Stadium

won by 5 Pallekele International Cricket


122 04/09/2016 Sri Lanka Australia Australia
wickets Stadium

won by 7
161 19/01/2017 Australia Pakistan Australia WACA Ground
wickets

won by 86
163 22/01/2017 Australia Pakistan Australia Sydney Cricket Ground
runs

won by 57
164 26/01/2017 Australia Pakistan Australia Adelaide Oval
runs

won by 3
285 26/01/2018 Australia England Australia Adelaide Oval
wickets

won by 32 JSCA International Stadium


403 08/03/2019 India Australia Australia
runs Complex

won by 4 Punjab Cricket Association IS


406 10/03/2019 India Australia Australia
wickets Bindra Stadium

won by 35
409 13/03/2019 India Australia Australia Arun Jaitley Stadium
runs

won by 8
411 22/03/2019 Pakistan Australia Australia Sharjah Cricket Stadium
wickets

won by 8
412 23/03/2019 Pakistan Australia Australia Sharjah Cricket Stadium
wickets

won by 80
413 27/03/2019 Pakistan Australia Australia Sheikh Zayed Stadium
runs

won by 6 Dubai International Cricket


414 29/03/2019 Pakistan Australia Australia
runs Stadium

won by 20 Dubai International Cricket


415 31/03/2019 Pakistan Australia Australia
runs Stadium

won by 7
438 01/06/2019 Afghanistan Australia Australia County Ground (Bristol)
wickets

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 12/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Date Team_1 Team_2 Winner Margin Ground

won by 64
468 25/06/2019 England Australia Australia Lord's
runs

New won by 71
517 13/03/2020 Australia Australia Sydney Cricket Ground
Zealand runs

won by 19
523 11/09/2020 England Australia Australia Old Trafford
runs

won by 3
525 16/09/2020 England Australia Australia Old Trafford
wickets

won by 66
528 27/11/2020 Australia India Australia Sydney Cricket Ground
runs

won by 51
529 29/11/2020 Australia India Australia Sydney Cricket Ground
runs

won by 133
568 20/07/2021 West Indies Australia Australia Kensington Oval
runs

won by 6
573 26/07/2021 West Indies Australia Australia Kensington Oval
wickets

won by 88
598 29/03/2022 Pakistan Australia Australia Gaddafi Stadium
runs

won by 2 Pallekele International Cricket


611 14/06/2022 Sri Lanka Australia Australia
wickets Stadium

won by 4
618 24/06/2022 Sri Lanka Australia Australia R Premadasa Stadium
wickets

won by 5
647 28/08/2022 Australia Zimbabwe Australia Riverway Stadium
wickets

won by 8
648 31/08/2022 Australia Zimbabwe Australia Riverway Stadium
wickets

New won by 2
650 06/09/2022 Australia Australia Cazaly's Stadium
Zealand wickets

New won by 113


651 08/09/2022 Australia Australia Cazaly's Stadium
Zealand runs

New won by 25
652 11/09/2022 Australia Australia Cazaly's Stadium
Zealand runs

won by 6
656 17/11/2022 Australia England Australia Adelaide Oval
wickets

won by 72
657 19/11/2022 Australia England Australia Sydney Cricket Ground
runs

won by 221
658 22/11/2022 Australia England Australia Melbourne Cricket Ground
runs

won by 10 Dr YS Rajasekhara Reddy


686 19/03/2023 India Australia Australia
wickets Cricket Stadium

won by 21
690 22/03/2023 India Australia Australia MA Chidambaram Stadium
runs

No.of wins for Australia against other teams

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 13/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [104… # Exclude Team Australia's name


excluded_value = 'Australia'

# Filtering out rows with the excluded value


filtered_df = Australia_win[Australia_win['Team_2'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()

# Print the value counts


print(value_counts)

England 4
New Zealand 4
Pakistan 2
India 2
Zimbabwe 2
South Africa 1
Pakistan 1
Name: Team_2, dtype: int64

In [105… # Exclude Team Australia's name


excluded_value = 'Australia'

# Filtering out rows with the excluded value


filtered_df = Australia_win[Australia_win['Team_1'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_1'].value_counts()

# Print the value counts


print(value_counts)

Sri Lanka 4
Pakistan 4
West Indies 3
India 3
England 2
Pakistan 2
England 2
West Indies 2
Sri Lanka 2
India 2
New Zealand 1
Afghanistan 1
Name: Team_1, dtype: int64

Displaying Team Australia's wins against other


teams using bar graph
In [106… # Exclude Team Austrlia
exclude = 'Australia'

# Filter out the opponent to exclude from the data


filtered_data = Australia_win[Australia_win['Team_2'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by Australlia.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_2'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 14/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [107… # Exclude Team Austrlia


exclude = 'Australia'

# Filter out the opponent to exclude from the data


filtered_data = Australia_win[Australia_win['Team_1'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by Australlia.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_1'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

Win Percentage of Australia Against Each Team


In [108… # Number of wins against each team
# Out of the 978 ODI matches played by Australia, number of matches won against the
team_win_counts = {
'India': 82,
'New Zealand': 95,
'South Africa ': 48,
'Pakistan': 69,
'Sri Lanka': 63,
'Bangladesh': 19,
'England': 87,
localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 15/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
'Netherlands': 2,
'Afghanistan': 3
}

# Total matches played is calculated


total_matches = sum(team_win_counts.values())

# Australia's win percentages against each team is calculated


win_percentages = {team: (wins / total_matches) * 100 for team, wins in team_win_co

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of Australia Against Each Team')

# Display the pie chart


plt.show()

Win Percentage of Australia in the ODI world cup


In [109… # Number of wins against each team in the ODI world cup
# Out of the 94 ODI matches played by Australia in the ODI world cup, number of mat
team_win_counts_wc_aus = {
'India': 8,
'New Zealand': 8,
'South Africa ': 3,
'Pakistan': 6,
'Sri Lanka': 8,
'Bangladesh': 3,
'England': 6,
'Netherlands': 2,
'Afghanistan': 2
}

# Total matches played is calculated


total_matches_wc_aus = sum(team_win_counts_wc_aus.values())

# Australia's win percentages against each team is calculated

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 16/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
win_percentages_wc_aus = {team: (wins / total_matches_wc_aus) * 100 for team, wins

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_aus.values(), labels=win_percentages_wc_aus.keys(), auto

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of Australia in the ODI world cup')

# Display the pie chart


plt.show()

Stats of Pakistan team


In [110… # Filter the 'results' DataFrame to include rows where Pakistan played either as Te
df2 = results[(results['Team_1'] == 'Pakistan') | (results['Team_2'] == 'Pakistan')

# Create a new DataFrame 'Pakistan' containing all rows from the filtered DataFrame
Pakistan = df2.iloc[:]

# Display the first few rows of the 'Pakistan' DataFrame


Pakistan.head()

Out[110]: Date Team_1 Team_2 Winner Margin Ground

won by 79
0 17/04/2015 Bangladesh Pakistan Bangladesh Shere Bangla National Stadium
runs

won by 7
1 19/04/2015 Bangladesh Pakistan Bangladesh Shere Bangla National Stadium
wickets

won by 8
2 22/04/2015 Bangladesh Pakistan Bangladesh Shere Bangla National Stadium
wickets

won by 6 Rangiri Dambulla International


17 11/07/2015 Sri Lanka Pakistan Pakistan
wickets Stadium

won by 2 Pallekele International Cricket


21 15/07/2015 Sri Lanka Pakistan Sri Lanka
wickets Stadium

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 17/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [111… # Filtering the 'Pakistan' dataframe to create a new dataframe 'Pakistan_win' conta
Pakistan_win = Pakistan[Pakistan['Winner']=='Pakistan']

In [112… Pakistan_win

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 18/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[112]: Date Team_1 Team_2 Winner Margin Ground

won by 6 Rangiri Dambulla International


17 11/07/2015 Sri Lanka Pakistan Pakistan
wickets Stadium

won by 135
23 19/07/2015 Sri Lanka Pakistan Pakistan R Premadasa Stadium
runs

won by 7
24 22/07/2015 Sri Lanka Pakistan Pakistan R Premadasa Stadium
wickets

won by 131
38 01/10/2015 Zimbabwe Pakistan Pakistan Harare Sports Club
runs

won by 7
40 05/10/2015 Zimbabwe Pakistan Pakistan Harare Sports Club
wickets

won by 255
111 18/08/2016 Ireland Pakistan Pakistan The Village
runs

won by 4
121 04/09/2016 England Pakistan Pakistan Sophia Gardens
wickets

won by 6
159 15/01/2017 Australia Pakistan Pakistan Melbourne Cricket Ground
wickets

won by 201
315 13/07/2018 Zimbabwe Pakistan Pakistan Queens Sports Club
runs

won by 9
317 16/07/2018 Zimbabwe Pakistan Pakistan Queens Sports Club
wickets

won by 9
319 18/07/2018 Zimbabwe Pakistan Pakistan Queens Sports Club
wickets

won by 244
320 20/07/2018 Zimbabwe Pakistan Pakistan Queens Sports Club
runs

won by 131
322 22/07/2018 Zimbabwe Pakistan Pakistan Queens Sports Club
runs

won by 8 Dubai International Cricket


336 16/09/2018 Hong Kong Pakistan Pakistan
wickets Stadium

won by 3
342 21/09/2018 Afghanistan Pakistan Pakistan Sheikh Zayed Stadium
wickets

won by 8
383 27/01/2019 South Africa Pakistan Pakistan Wanderers Stadium
wickets

won by 14
440 03/06/2019 England Pakistan Pakistan Trent Bridge
runs

New won by 6
469 26/06/2019 Pakistan Pakistan Edgbaston
Zealand wickets

won by 3
472 29/06/2019 Afghanistan Pakistan Pakistan Headingley
wickets

won by 67
491 30/09/2019 Pakistan Sri Lanka Pakistan National Stadium (Karachi)
runs

won by 5
492 02/10/2019 Pakistan Sri Lanka Pakistan National Stadium (Karachi)
wickets

won by 26
526 30/10/2020 Pakistan Zimbabwe Pakistan Rawalpindi Cricket Stadium
runs

won by 6
527 01/11/2020 Pakistan Zimbabwe Pakistan Rawalpindi Cricket Stadium
wickets

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 19/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Date Team_1 Team_2 Winner Margin Ground

won by 3
545 02/04/2021 South Africa Pakistan Pakistan SuperSport Park
wickets

won by 28
547 07/04/2021 South Africa Pakistan Pakistan SuperSport Park
runs

won by 6
599 31/03/2022 Pakistan Australia Pakistan Gaddafi Stadium
wickets

won by 9
600 02/04/2022 Pakistan Australia Pakistan Gaddafi Stadium
wickets

won by 5
607 08/06/2022 Pakistan West Indies Pakistan Multan Cricket Stadium
wickets

won by 120
609 10/06/2022 Pakistan West Indies Pakistan Multan Cricket Stadium
runs

won by 53
610 12/06/2022 Pakistan West Indies Pakistan Multan Cricket Stadium
runs

won by 16
638 16/08/2022 Netherlands Pakistan Pakistan Hazelaarweg
runs

won by 7
641 18/08/2022 Netherlands Pakistan Pakistan Hazelaarweg
wickets

won by 9
644 21/08/2022 Netherlands Pakistan Pakistan Hazelaarweg
runs

New won by 6
668 09/01/2023 Pakistan Pakistan National Stadium (Karachi)
Zealand wickets

New won by 5
698 27/04/2023 Pakistan Pakistan Rawalpindi Cricket Stadium
Zealand wickets

New won by 7
699 29/04/2023 Pakistan Pakistan Rawalpindi Cricket Stadium
Zealand wickets

New won by 26
700 03/05/2023 Pakistan Pakistan National Stadium (Karachi)
Zealand runs

New won by 102


701 05/05/2023 Pakistan Pakistan National Stadium (Karachi)
Zealand runs

No.of wins for Pakistan against other teams


In [113… # Exclude Team Pakistan's name
excluded_value = 'Pakistan'

# Filtering out rows with the excluded value


filtered_df = Pakistan_win[Pakistan_win['Team_2'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()

# Print the value counts


print(value_counts)

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 20/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
New Zealand 5
West Indies 3
Sri Lanka 2
Zimbabwe 2
Australia 2
Name: Team_2, dtype: int64

In [114… # Exclude Team Pakistan's name


excluded_value = 'Pakistan'

# Filtering out rows with the excluded value


filtered_df = Pakistan_win[Pakistan_win['Team_1'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_1' colum
value_counts = filtered_df['Team_1'].value_counts()

# Print the value counts


print(value_counts)

Zimbabwe 7
Sri Lanka 3
Netherlands 3
England 2
Afghanistan 2
South Africa 2
Ireland 1
Australia 1
Hong Kong 1
South Africa 1
New Zealand 1
Name: Team_1, dtype: int64

Displaying Team Pakistan's wins against other teams


using bar graph
In [115… # Exclude Team Pakistan
exclude = 'Pakistan'

# Filter out the opponent to exclude from the data


filtered_data = Pakistan_win[Pakistan_win['Team_2'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by Pakistan.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_2'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 21/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [116… # Exclude Team Pakistan


exclude = 'Pakistan'

# Filter out the opponent to exclude from the data


filtered_data = Pakistan_win[Pakistan_win['Team_1'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by Pakistan.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_1'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

Win Percentage of Pakistan Against Each Team


In [117… # Number of wins against each team
# Out of the 945 ODI matches played by Pakistan, number of matches won against the
team_win_counts = {
'India': 73,
'New Zealand': 60,
'South Africa ': 30,
'Australia': 34,
'Sri Lanka': 92,
'Bangladesh': 32,
'England': 32,
localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 22/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
'Netherlands': 3,
'Afghanistan': 7
}

# Total matches played is calculated


total_matches = sum(team_win_counts.values())

# Pakistan's win percentages against each team is calculated


win_percentages = {team: (wins / total_matches) * 100 for team, wins in team_win_co

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of Pakistan Against Each Team')

# Display the pie chart


plt.show()

Win Percentage of Pakistan in the ODI world cup


In [118… # Number of wins against each team in the ODI world cup
# Out of the 79 ODI matches played by Pakistan in the ODI world cup, number of matc
team_win_counts_wc_pak = {
'India': 0,
'New Zealand': 7,
'South Africa ': 2,
'Australia': 4,
'Sri Lanka': 7,
'Bangladesh': 1,
'England': 5,
'Afghanistan': 1
}

# Total matches played is calculated


total_matches_wc_pak = sum(team_win_counts_wc_pak.values())

# Pakistan's win percentages against each team is calculated


win_percentages_wc_pak = {team: (wins / total_matches_wc_pak) * 100 for team, wins

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 23/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_pak.values(), labels=win_percentages_wc_pak.keys(), auto

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of Pakistan in the ODI world cup')

# Display the pie chart


plt.show()

Stats of New Zealand team


In [119… # Filter the 'results' DataFrame to include rows where New Zealand played either as
df3 = results[(results['Team_1'] == 'New Zealand') | (results['Team_2'] == 'New Zea

# Create a new DataFrame 'New Zealand' containing all rows from the filtered DataFr
New_Zealand = df3.iloc[:]

# Display the first few rows of the 'India' DataFrame


New_Zealand.head()

Out[119]: Date Team_1 Team_2 Winner Margin Ground

7 09/06/2015 England New Zealand England won by 210 runs Edgbaston

8 12/06/2015 England New Zealand New Zealand won by 13 runs Kennington Oval

9 14/06/2015 England New Zealand New Zealand won by 3 wickets The Rose Bowl

10 17/06/2015 England New Zealand England won by 7 wickets Trent Bridge

12 20/06/2015 England New Zealand England won by 3 wickets Riverside Ground

In [120… # Filtering the 'New_Zealand' dataframe to create a new dataframe 'nz_win' containi
nz_win = New_Zealand[New_Zealand['Winner']=='New Zealand']

In [121… nz_win

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 24/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[121]: Date Team_1 Team_2 Winner Margin Ground

New New won by 10


27 04/08/2015 Zimbabwe Harare Sports Club
Zealand Zealand wickets

New New won by 38


28 07/08/2015 Zimbabwe Harare Sports Club
Zealand Zealand runs

New New won by 3


76 31/01/2016 Pakistan Eden Park
Zealand Zealand wickets

New New won by 55


81 08/02/2016 Australia Seddon Park
Zealand Zealand runs

New New won by 6


140 20/10/2016 India Arun Jaitley Stadium
Zealand Zealand runs

New New won by 19 JSCA International Stadium


142 26/10/2016 India
Zealand Zealand runs Complex

New New won by 77


154 26/12/2016 Bangladesh Hagley Oval
Zealand Zealand runs

New New won by 51


200 14/05/2017 Ireland The Village
Zealand Zealand runs

New New won by 61


271 06/01/2018 Pakistan Basin Reserve
Zealand Zealand runs

New New won by 47


365 07/11/2018 Pakistan Sheikh Zayed Stadium
Zealand Zealand runs

New New won by 45


372 03/01/2019 Sri Lanka Bay Oval
Zealand Zealand runs

New New won by 8


389 16/02/2019 Bangladesh Hagley Oval
Zealand Zealand wickets

New New won by 2


443 05/06/2019 Bangladesh Kennington Oval
Zealand Zealand wickets

New New won by 7 The Cooper Associates


447 08/06/2019 Afghanistan
Zealand Zealand wickets County Ground

New New won by 4


460 19/06/2019 South Africa Edgbaston
Zealand Zealand wickets

New New won by 18


481 09/07/2019 India Old Trafford
Zealand Zealand runs

New New won by 4


502 05/02/2020 India Seddon Park
Zealand Zealand wickets

New New won by 22


504 08/02/2020 India Eden Park
Zealand Zealand runs

New New won by 5


506 11/02/2020 India Bay Oval
Zealand Zealand wickets

New New won by 8


539 20/03/2021 Bangladesh University Oval
Zealand Zealand wickets

New New won by 5


541 23/03/2021 Bangladesh Hagley Oval
Zealand Zealand wickets

New New won by 164


543 26/03/2021 Bangladesh Basin Reserve
Zealand Zealand runs

New New won by 7


597 29/03/2022 Netherlands Bay Oval
Zealand Zealand wickets

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 25/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Date Team_1 Team_2 Winner Margin Ground

New New won by 118


601 03/04/2022 Netherlands Seddon Park
Zealand Zealand runs

New New won by 115


602 04/04/2022 Netherlands Seddon Park
Zealand Zealand runs

New New won by 1


619 10/07/2022 Ireland The Village
Zealand Zealand wicket

New New won by 3


622 12/07/2022 Ireland The Village
Zealand Zealand wickets

New New
625 15/07/2022 Ireland won by 1 run The Village
Zealand Zealand

New New won by 7


634 31/07/2022 Scotland Grange Cricket Club
Zealand Zealand wickets

New New won by 50


642 19/08/2022 West Indies Kensington Oval
Zealand Zealand runs

New New won by 5


645 21/08/2022 West Indies Kensington Oval
Zealand Zealand wickets

New New won by 7


659 25/11/2022 India Eden Park
Zealand Zealand wickets

New New won by 79


670 11/01/2023 Pakistan National Stadium (Karachi)
Zealand Zealand runs

New New won by 198


693 25/03/2023 Sri Lanka Eden Park
Zealand Zealand runs

New New won by 6


697 31/03/2023 Sri Lanka Seddon Park
Zealand Zealand wickets

New New won by 47


702 07/05/2023 Pakistan National Stadium (Karachi)
Zealand Zealand runs

No.of wins for New Zealand in ODIs against other


teams
In [122… # Exclude Team New Zealand's name
excluded_value = 'New Zealand'

# Filtering out rows with the excluded value


filtered_df = nz_win[nz_win['Team_2'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()

# Print the value counts


print(value_counts)

Bangladesh 5
India 4
Sri Lanka 3
Netherlands 3
Pakistan 2
Australia 1
South Africa 1
Name: Team_2, dtype: int64

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 26/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [123… # Exclude Team New Zealand's name


excluded_value = 'New Zealand'

# Filtering out rows with the excluded value


filtered_df = nz_win[nz_win['Team_1'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_1'].value_counts()

# Print the value counts


print(value_counts)

India 3
Pakistan 3
Ireland 3
Zimbabwe 2
West Indies 2
Ireland 1
Bangladesh 1
Afghanistan 1
Scotland 1
Name: Team_1, dtype: int64

Displaying Team New Zealand's wins against other


teams using bar graph
In [124… # Exclude Team New Zealand
exclude = 'New Zealand'

# Filter out the opponent to exclude from the data


filtered_data = nz_win[nz_win['Team_2'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by New Zealand.
plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_2'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

In [125… # Exclude Team New Zealand


exclude = 'New Zealand'

# Filter out the opponent to exclude from the data


filtered_data = nz_win[nz_win['Team_1'] != exclude]

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 27/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

# Plotting a bar chart to show the top 5 opponents faced by New Zealand.
plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_1'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

Win Percentage of New Zealand Against Each Team


In [126… # Number of wins against each team
# Out of the 794 ODI matches played by New Zealand, number of matches won against t
team_win_counts = {
'Australia': 39,
'India': 50,
'South Africa ': 26,
'Pakistan': 50,
'Sri Lanka': 49,
'Bangladesh':28,
'England': 42,
'Netherlands': 4,
'Afghanistan': 2
}

# Total matches played is calculated


total_matches = sum(team_win_counts.values())

# New Zealand's's win percentages against each team is calculated


win_percentages = {team: (wins / total_matches) * 100 for team, wins in team_win_co

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of New Zealand Against Each Team')

# Display the pie chart


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 28/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Win Percentage of New Zealand in the ODI world


cup
In [127… # Number of wins against each team in the ODI world cup
# Out of the 89 ODI matches played by New Zealand in the ODI world cup, number of m
team_win_counts_wc_nz = {
'Australia': 3,
'India': 5,
'South Africa ': 5,
'Pakistan': 2,
'Sri Lanka': 5,
'Bangladesh': 5,
'England': 5,
'Netherlands': 4,
'Afghanistan': 2
}

# Total matches played is calculated


total_matches_wc_nz = sum(team_win_counts_wc_nz.values())

# New Zealand's win percentages against each team is calculated


win_percentages_wc_nz = {team: (wins / total_matches_wc_nz) * 100 for team, wins in

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_nz.values(), labels=win_percentages_wc_nz.keys(), autopc

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of New Zealand in the ODI world cup')

# Display the pie chart


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 29/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Stats of Pakistan team


In [128… # Filter the 'results' DataFrame to include rows where England played either as Tea
df4 = results[(results['Team_1'] == 'England') | (results['Team_2'] == 'England')]

# Create a new DataFrame 'England' containing all rows from the filtered DataFrame
England = df4.iloc[:]

# Display the first few rows of the 'England' DataFrame


England.head()

Out[128]: Date Team_1 Team_2 Winner Margin Ground

New New
8 12/06/2015 England won by 13 runs Kennington Oval
Zealand Zealand

35 08/09/2015 England Australia England won by 93 runs Old Trafford

Pakistan won by 6
55 11/11/2015 Pakistan England Pakistan Sheikh Zayed Stadium
wickets

England won by 95
57 13/11/2015 Pakistan England England Sheikh Zayed Stadium
runs

England won by 6 Sharjah Cricket


58 17/11/2015 Pakistan England England
wickets Stadium

In [129… # Filtering the 'England' dataframe to create a new dataframe 'England_win' contain
England_win = England[England['Winner']=='England']

In [130… England_win

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 30/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[130]: Date Team_1 Team_2 Winner Margin Ground

35 08/09/2015 England Australia England won by 93 runs Old Trafford

Dubai International
59 20/11/2015 Pakistan England England England won by 84 runs
Cricket Stadium

78 03/02/2016 South Africa England England won by 39 runs Mangaung Oval

80 06/02/2016 South Africa England England won by 5 wickets St George's Park

Shere Bangla National


134 07/10/2016 Bangladesh England England won by 21 runs
Stadium

Zahur Ahmed
137 12/10/2016 Bangladesh England England won by 4 wickets
Chowdhury Stadium

185 09/03/2017 West Indies England England won by 186 runs Kensington Oval

Melbourne Cricket
274 14/01/2018 Australia England England won by 5 wickets
Ground

Brisbane Cricket
278 18/01/2018 Australia England England won by 4 wickets
Ground

Sydney Cricket
281 21/01/2018 Australia England England won by 16 runs
Ground

287 28/01/2018 Australia England England won by 12 runs Perth Stadium

New
300 28/02/2018 England England won by 6 wickets Bay Oval
Zealand

New
301 03/03/2018 England England won by 4 runs Sky Stadium
Zealand

New
304 10/03/2018 England England won by 7 wickets Hagley Oval
Zealand

Rangiri Dambulla
352 13/10/2018 Sri Lanka England England won by 31 runs
International Stadium

Pallekele International
353 17/10/2018 Sri Lanka England England won by 7 wickets
Cricket Stadium

Pallekele International
354 20/10/2018 Sri Lanka England England won by 18 runs
Cricket Stadium

416 03/05/2019 Ireland England England won by 4 wickets The Village

423 11/05/2019 England Pakistan England won by 12 runs The Rose Bowl

County Ground
426 14/05/2019 England Pakistan England won by 6 wickets
(Bristol)

West
453 14/06/2019 England England won by 8 wickets The Rose Bowl
Indies

474 30/06/2019 England India England won by 31 runs Edgbaston

New
477 03/07/2019 England England won by 119 runs Riverside Ground
Zealand

won on boundary count


New
483 14/07/2019 England England after scores and super Lord's
Zealand
o...

505 09/02/2020 South Africa England England won by 2 wickets Wanderers Stadium

520 30/07/2020 England Ireland England won by 6 wickets The Rose Bowl

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 31/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Date Team_1 Team_2 Winner Margin Ground

521 01/08/2020 England Ireland England won by 4 wickets The Rose Bowl

524 13/09/2020 England Australia England won by 24 runs Old Trafford

Maharashtra Cricket
542 26/03/2021 India England England won by 6 wickets
Association Stadium

556 29/06/2021 England Sri Lanka England won by 5 wickets Riverside Ground

557 01/07/2021 England Sri Lanka England won by 8 wickets Kennington Oval

559 08/07/2021 England Pakistan England won by 9 wickets Sophia Gardens

560 10/07/2021 England Pakistan England won by 52 runs Lord's

563 13/07/2021 England Pakistan England won by 3 wickets Edgbaston

613 17/06/2022 Netherlands England England won by 232 runs VRA Ground

614 19/06/2022 Netherlands England England won by 6 wickets VRA Ground

617 22/06/2022 Netherlands England England won by 8 wickets VRA Ground

624 14/07/2022 England India England won by 100 runs Lord's

South
630 22/07/2022 England England won by 118 runs Old Trafford
Africa

678 01/02/2023 South Africa England England won by 59 runs Diamond Oval

Shere Bangla National


679 01/03/2023 Bangladesh England England won by 3 wickets
Stadium

Shere Bangla National


680 03/03/2023 Bangladesh England England won by 132 runs
Stadium

No.of wins for England against other teams


In [131… # Exclude Team Englans's name
excluded_value = 'England'

# Filtering out rows with the excluded value


filtered_df = England_win[England_win['Team_2'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()

# Print the value counts


print(value_counts)

Pakistan 5
Australia 2
India 2
New Zealand 2
Ireland 2
Sri Lanka 2
West Indies 1
South Africa 1
Name: Team_2, dtype: int64

In [132… # Exclude Team England's name


excluded_value = 'England'

# Filtering out rows with the excluded value

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 32/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
filtered_df = England_win[England_win['Team_1'] != excluded_value]

# Counting the occurrences of each value in the filtered DataFrame's 'Team_1' colum
value_counts = filtered_df['Team_1'].value_counts()

# Print the value counts


print(value_counts)

Australia 4
Netherlands 3
South Africa 2
Bangladesh 2
New Zealand 2
Sri Lanka 2
South Africa 2
Bangladesh 2
Pakistan 1
West Indies 1
New Zealand 1
Sri Lanka 1
Ireland 1
India 1
Name: Team_1, dtype: int64

Displaying Team England's wins against other teams


using bar graph
In [133… # Exclude Team England
exclude = 'England'

# Filter out the opponent to exclude from the data


filtered_data = England_win[England_win['Team_2'] != exclude]

# Plotting a bar chart to show the top 5 opponents faced by England.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_2'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

In [134… # Exclude Team England


exclude = 'England'

# Filter out the opponent to exclude from the data


filtered_data = England_win[England_win['Team_1'] != exclude]
localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 33/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

# Plotting a bar chart to show the top 5 opponents faced by England.


plt.figure(figsize=(8, 5))
plt.bar(list(filtered_data['Team_1'].value_counts()[0:5].keys()), list(filtered_dat
plt.show()

Win Percentage of England Against Each Team


In [135… # Number of wins against each team
# Out of the 775 ODI matches played by England, number of matches won against the f
team_win_counts = {
'India': 44,
'New Zealand': 42,
'South Africa ': 29,
'Australia': 63,
'Sri Lanka': 38,
'Bangladesh': 19,
'Pakistan': 56,
'Netherlands': 6,
'Afghanistan': 2
}

# Total matches played is calculated


total_matches = sum(team_win_counts.values())

# England's win percentages against each team is calculated


win_percentages = {team: (wins / total_matches) * 100 for team, wins in team_win_co

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of England Against Each Team')

# Display the pie chart


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 34/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [136… # Number of wins against each team in the ODI world cup
# Out of the 83 ODI matches played by England in the ODI world cup, number of match
team_win_counts_wc_eng = {
'Australia': 3,
'India': 4,
'South Africa ': 4,
'Pakistan': 4,
'Sri Lanka': 6,
'Bangladesh': 5,
'New Zealand': 5,
'Netherlands': 4,
'Afghanistan': 2
}

# Total matches played is calculated


total_matches_wc_eng= sum(team_win_counts_wc_eng.values())

# England's win percentages against each team is calculated


win_percentages_wc_eng = {team: (wins / total_matches_wc_eng) * 100 for team, wins

# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_eng.values(), labels=win_percentages_wc_eng.keys(), auto

# Equal aspect ratio ensures that pie is drawn as a circle.


plt.axis('equal')

# Title for the pie chart


plt.title('Win Percentage of England in the ODI world cup')

# Display the pie chart


plt.show()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 35/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Exploratory data analysis


In [137… # This is a list of cricket teams participating in the world cup.
worldcup_teams = ['England', ' South Africa', '', 'West Indies',
'Pakistan', 'New Zealand', 'Sri Lanka', 'Afghanistan',
'Australia', 'Bangladesh', 'India']

# Filtering matches involving only teams in the 'worldcup_teams' list


df_teams_1 = results[results['Team_1'].isin(worldcup_teams)] # Extracts matches wi
df_teams_2 = results[results['Team_2'].isin(worldcup_teams)] # Extracts matches wi

# Combining the filtered dataframes


df_teams = pd.concat((df_teams_1, df_teams_2)) # Concatenates the two dataframes v

df_teams.drop_duplicates() # Removes duplicate rows if any

df_teams.count() # Counts the number of rows in the final dataframe

Date 748
Out[137]:
Team_1 748
Team_2 748
Winner 748
Margin 748
Ground 748
dtype: int64

In [138… # Displaying the first few rows of the "df_teams" DataFrame.


df_teams.head()

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 36/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[138]: Date Team_1 Team_2 Winner Margin Ground

New New
8 12/06/2015 England won by 13 runs Kennington Oval
Zealand Zealand

Shere Bangla National


11 18/06/2015 Bangladesh India Bangladesh won by 79 runs
Stadium

35 08/09/2015 England Australia England won by 93 runs Old Trafford

Sri Lanka won by Pallekele International


53 07/11/2015 Sri Lanka West Indies Sri Lanka
19 runs Cricket Stadium

Bangladesh won Shere Bangla National


56 11/11/2015 Bangladesh Zimbabwe Bangladesh
by 61 runs Stadium

In [139… # Removing unnecessary columns from df_teams and displaying the first few rows of t
df_teams_2019 = df_teams.drop(['Date','Margin', 'Ground'], axis=1)
df_teams_2019.head()

Out[139]: Team_1 Team_2 Winner

8 England New Zealand New Zealand

11 Bangladesh India Bangladesh

35 England Australia England

53 Sri Lanka West Indies Sri Lanka

56 Bangladesh Zimbabwe Bangladesh

In [140… df_teams_2019

Out[140]: Team_1 Team_2 Winner

8 England New Zealand New Zealand

11 Bangladesh India Bangladesh

35 England Australia England

53 Sri Lanka West Indies Sri Lanka

56 Bangladesh Zimbabwe Bangladesh

... ... ... ...

716 Bangladesh Afghanistan Afghanistan

718 Sri Lanka West Indies Sri Lanka

719 Bangladesh Afghanistan Afghanistan

720 Netherlands Sri Lanka Sri Lanka

721 Bangladesh Afghanistan Bangladesh

748 rows × 3 columns

Feature selection
In [141… # Reset the index of df_teams_2019 while dropping the old index.
df_teams_2019 = df_teams_2019.reset_index(drop=True)

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 37/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

# Set a value of 1 in the 'winning_team' column for rows where the 'Winner' column
df_teams_2019.loc[df_teams_2019.Winner == df_teams_2019.Team_1,'winning_team']=1

# Set a value of 2 in the 'winning_team' column for rows where the 'Winner' column
df_teams_2019.loc[df_teams_2019.Winner == df_teams_2019.Team_2, 'winning_team']=2

# Drop the 'winning_team' column from the DataFrame.


df_teams_2019 = df_teams_2019.drop(['winning_team'], axis=1)

# Display the first few rows of the modified DataFrame using df_teams_2019.head().
df_teams_2019.head()

Out[141]: Team_1 Team_2 Winner

0 England New Zealand New Zealand

1 Bangladesh India Bangladesh

2 England Australia England

3 Sri Lanka West Indies Sri Lanka

4 Bangladesh Zimbabwe Bangladesh

Training and testing the data


In [142… # Importing train_test_split from sklearn.model_selection
from sklearn.model_selection import train_test_split

In [143… # Creating dummy variables for team names


final = pd.get_dummies(df_teams_2019, prefix=['Team_1', 'Team_2'], columns=['Team_1

X = final.drop(['Winner'], axis=1) # Extracting features by dropping the 'Winner'


y = final["Winner"] # Assigning the 'Winner' column as the target variable

# Split the data into training and testing sets using a test size of 20% and a rand
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_st

In [144… final.head()

Out[144]:
Winner Team_1_Afghanistan Team_1_Afghanistan Team_1_Australia Team_1_Australia Team

New
0 0 0 0 0
Zealand

1 Bangladesh 0 0 0 0

2 England 0 0 0 0

3 Sri Lanka 0 0 0 0

4 Bangladesh 0 0 0 0

5 rows × 51 columns

Applying Random forest classifier algorithm


localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 38/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [145… # Import the Random forest module from sklearn


from sklearn.ensemble import RandomForestClassifier

# Create an Random forest classifier with a linear kernel


rf = RandomForestClassifier(n_estimators=100, max_depth=20,
random_state=0)

# Fit the classifier on the training data


rf.fit(X_train, y_train)

# Make predictions on the test data


pred = rf.predict(X_test)

# Calculating training set score:


score = rf.score(X_train, y_train)

# Calculating test set score:


score2 = rf.score(X_test, y_test)

# Printing the training set accuracy with 3 decimal places


print("Training set accuracy: ", '%.3f'%(score))

# Printing the test set accuracy with 3 decimal places


print("Test set accuracy: ", '%.3f'%(score2))

Training set accuracy: 0.749


Test set accuracy: 0.673

Evaluating the best model on test data


In [146… ranking = pd.read_csv('Icc_ranking.csv') # Read the ICC rankings from the 'Icc_ran
fixtures = pd.read_csv('Fixtures.csv') # Read the fixtures from the 'Fixtures.cs

pred_set = [] # Initialize an empty list to store prediction results

In [147… # Code to insert team rankings into the fixtures dataframe based on 'Team_1' and 'T
fixtures.insert(1, 'first_position', fixtures['Team_1'].map(ranking.set_index('Team
fixtures.insert(2, 'second_position', fixtures['Team_2'].map(ranking.set_index('Tea

# Select the first 45 rows of the updated fixtures dataframe.


fixtures = fixtures.iloc[:45, :]
fixtures.head() # Display the first few rows of the updated dataframe.

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 39/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Out[147]: Round_number first_position second_position Team_1 Team_2 Date Location

Narendra
New Mod
0 1 5.0 NaN England 5/10/2023
Zealand Stadium
Ahmedabad

Rajiv Gandh
Internationa
1 1 NaN 10.0 Pakistan Netherlands 6/10/2023
Stadium
Hyderabad

Himacha
Pradesh
2 1 7.0 8.0 Bangladesh Afghanistan 7/10/2023 Cricke
Association
Stadium, .

Arun Jaitley
South
3 1 6.0 9.0 Sri Lanka 7/10/2023 Stadium
Africa
Delh

MA
Chidambaram
4 1 3.0 1.0 India Australia 8/10/2023
Stadium
Chenna

In [148… # Filling missing values in 'first_position' and 'second_position' columns with the
fixtures['first_position']=fixtures['first_position'].fillna(fixtures['first_positi
fixtures['second_position']=fixtures['second_position'].fillna(fixtures['second_pos
fixtures.head()

Out[148]: Round_number first_position second_position Team_1 Team_2 Date Location

Narendra
New Mod
0 1 5.000000 7.119048 England 5/10/2023
Zealand Stadium
Ahmedabad

Rajiv Gandh
Internationa
1 1 4.411765 10.000000 Pakistan Netherlands 6/10/2023
Stadium
Hyderabad

Himacha
Pradesh
2 1 7.000000 8.000000 Bangladesh Afghanistan 7/10/2023 Cricke
Association
Stadium, .

Arun Jaitley
South
3 1 6.000000 9.000000 Sri Lanka 7/10/2023 Stadium
Africa
Delh

MA
Chidambaram
4 1 3.000000 1.000000 India Australia 8/10/2023
Stadium
Chenna

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 40/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

In [149… # Predicting winning teams based on positions in fixtures.


for index, row in fixtures.iterrows():
if row['first_position'] < row['second_position']:
pred_set.append({'Team_1': row['Team_1'], 'Team_2': row['Team_2'], 'winning
else:
pred_set.append({'Team_1': row['Team_2'], 'Team_2': row['Team_1'], 'winning

pred_set = pd.DataFrame(pred_set) # Creating a DataFrame for pred_set.


backup_pred_set = pred_set # Creating a backup of the pred_set DataFrame
pred_set.head() # Displaying the first few rows of the pred_set DataFrame

Out[149]: Team_1 Team_2 winning_team

0 England New Zealand None

1 Pakistan Netherlands None

2 Bangladesh Afghanistan None

3 South Africa Sri Lanka None

4 Australia India None

In [150… # Transforming the dataset using one-hot encoding for 'Team_1' and 'Team_2' columns
pred_set = pd.get_dummies(pred_set, prefix=['Team_1', 'Team_2'], columns=['Team_1',

# Finding missing columns in the final dataset compared to the transformed 'pred_se
missing_cols = set(final.columns) - set(pred_set.columns)

# Setting the missing columns in "pred_set" DataFrame to 0 and then keeps only the
for c in missing_cols:
pred_set[c] = 0
pred_set = pred_set[final.columns]

# Dropping the 'Winner' column from pred_set.


pred_set = pred_set.drop(['Winner'], axis=1)
pred_set.head()

Out[150]:
Team_1_Afghanistan Team_1_Afghanistan Team_1_Australia Team_1_Australia Team_1_Banglades

0 0 0 0 0

1 0 0 0 0

2 0 0 0 0

3 0 0 0 0

4 0 0 1 0

5 rows × 50 columns

Interpret the model results


In [151… # Making predictions using 'rf' on 'pred_set' and printing the winners for each fix
predictions = rf.predict(pred_set)
for i in range(fixtures.shape[0]):
print(backup_pred_set.iloc[i, 1] + " vs " + backup_pred_set.iloc[i, 0])
if predictions[i] == 1:

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 41/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
print("Winner: " + backup_pred_set.iloc[i, 1])

else:
print("Winner: " + backup_pred_set.iloc[i, 0])
print("")

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 42/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
New Zealand vs England
Winner: England

Netherlands vs Pakistan
Winner: Pakistan

Afghanistan vs Bangladesh
Winner: Bangladesh

Sri Lanka vs South Africa


Winner: South Africa

India vs Australia
Winner: Australia

Netherlands vs New Zealand


Winner: New Zealand

Bangladesh vs England
Winner: England

Afghanistan vs India
Winner: India

Sri Lanka vs Pakistan


Winner: Pakistan

South Africa vs Australia


Winner: Australia

Bangladesh vs New Zealand


Winner: New Zealand

Afghanistan vs England
Winner: England

India vs Pakistan
Winner: Pakistan

Sri Lanka vs Australia


Winner: Australia

Netherlands vs South Africa


Winner: South Africa

Afghanistan vs New Zealand


Winner: New Zealand

Bangladesh vs India
Winner: India

Pakistan vs Australia
Winner: Australia

Netherlands vs Sri Lanka


Winner: Sri Lanka

South Africa vs England


Winner: England

New Zealand vs India


Winner: India

Afghanistan vs Pakistan

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 43/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction
Winner: Pakistan

Bangladesh vs South Africa


Winner: South Africa

Netherlands vs Australia
Winner: Australia

Sri Lanka vs England


Winner: England

South Africa vs Pakistan


Winner: Pakistan

New Zealand vs Australia


Winner: Australia

Netherlands vs Bangladesh
Winner: Bangladesh

England vs India
Winner: India

Sri Lanka vs Afghanistan


Winner: Afghanistan

Bangladesh vs Pakistan
Winner: Pakistan

South Africa vs New Zealand


Winner: New Zealand

Sri Lanka vs India


Winner: India

Netherlands vs Afghanistan
Winner: Afghanistan

New Zealand vs Pakistan


Winner: Pakistan

England vs Australia
Winner: Australia

South Africa vs India


Winner: India

Sri Lanka vs Bangladesh


Winner: Bangladesh

Afghanistan vs Australia
Winner: Australia

Netherlands vs England
Winner: England

Sri Lanka vs New Zealand


Winner: New Zealand

Afghanistan vs South Africa


Winner: South Africa

Netherlands vs India
Winner: India

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 44/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

Bangladesh vs Australia
Winner: Australia

England vs Pakistan
Winner: Pakistan

In [152… # The teams qualified for semi-finals based on wins.


semi = [('Pakistan', 'Australia'),
('England', 'India')]

In [153… def clean_and_predict(matches, ranking, final, rf):


# Initialize an empty list to store the positions of teams in the ranking
positions = []

# Loop through the list of matches and add the rankings of the teams to the pos
for match in matches:
positions.append(ranking.loc[ranking['Team_name'] == match[0], 'Team_rankin
positions.append(ranking.loc[ranking['Team_name'] == match[0], 'Team_rankin

# Initialize an empty list to store the match predictions


pred_set = []

# Initialize indices i and j to 0 for iteration


i = 0
j = 0

# Loop through the positions list to create match predictions


while i < len(positions):
dict1 = {}
# Compare the positions of the two teams in the match
# and add the corresponding team names to the prediction dictionary
if positions[i] < positions[i + 1]:
dict1.update({'Team_1': matches[j][0], 'Team_2': matches[j][1]})
else:
dict1.update({'Team_1': matches[j][1], 'Team_2': matches[j][0]})

# Add the prediction dictionary to the pred_set list


pred_set.append(dict1)
i += 2
j += 1

# Convert the pred_set list into a pandas DataFrame


pred_set = pd.DataFrame(pred_set)

# Make a backup of the pred_set DataFrame


backup_pred_set = pred_set

# Convert categorical variables in the pred_set DataFrame into dummy variables


pred_set = pd.get_dummies(pred_set, prefix=['Team_1', 'Team_2'], columns=['Team

# Identify missing columns in pred_set compared to the final DataFrame


missing_cols2 = set(final.columns) - set(pred_set.columns)

# Add the missing columns to the pred_set DataFrame and set their values to 0
for c in missing_cols2:
pred_set[c] = 0

# Reorder pred_set columns to match the final DataFrame's order


pred_set = pred_set[final.columns]

# Drop the 'Winner' column from the pred_set DataFrame


pred_set = pred_set.drop(['Winner'], axis=1)
localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 45/46
11/4/23, 12:54 AM icc-worldcup-2023-winner-prediction

# Use the provided classifier (cls) to make predictions on the pred_set DataFra
predictions = rf.predict(pred_set)

# Loop through the pred_set DataFrame and print the match predictions and winne
for i in range(len(pred_set)):
print(backup_pred_set.iloc[i, 1] + " vs " + backup_pred_set.iloc[i, 0])
if predictions[i] == 1:
print("Winner: " + backup_pred_set.iloc[i, 1])
else:
print("Winner: " + backup_pred_set.iloc[i, 0])
print("")

# Call the clean_and_predict function with the provided arguments


clean_and_predict(semi, ranking, final, rf)

Pakistan vs Australia
Winner: Australia

England vs India
Winner: India

In [154… # The teams qualified for the Finals


finals = [('Australia', 'India')]

Conclusion
In [82]: # Clean the data, apply ranking and use the classifier to predict the final outcome
clean_and_predict(finals, ranking, final, rf)

Australia vs India
Winner: India

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

localhost:8890/nbconvert/html/icc-worldcup-2023-winner-prediction.ipynb?download=false 46/46

You might also like