Professional Documents
Culture Documents
Icc Worldcup 2023 Winner Prediction Output PDF
Icc Worldcup 2023 Winner Prediction Output PDF
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")
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
6 Bangladesh 7 0 36.65 40 14
7 Afghanistan 8 0 49.65 15 1
9 Netherlands 10 0 34.21 20 2
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
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)})
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)
# Create a new DataFrame 'India' containing all rows from the filtered DataFrame
India = df.iloc[:]
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
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
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
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
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
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
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 4
498 22/12/2019 India India Barabati Stadium
Indies wickets
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 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
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
South won by 7
655 11/10/2022 India India Arun Jaitley Stadium
Africa wickets
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 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
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()
West Indies 6
New Zealand 4
Australia 3
Sri Lanka 3
England 2
South Africa 2
Name: Team_2, dtype: int64
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_1'].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
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
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',
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
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_ind.values(), labels=win_percentages_wc_ind.keys(), auto
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
# Create a new DataFrame 'Australia' containing all rows from the filtered DataFram
Australia = df1.iloc[:]
32 27/08/2015 Ireland Australia Australia won by 23 runs Civil Service Cricket Club
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
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 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 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 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
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 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 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 21
690 22/03/2023 India Australia Australia MA Chidambaram Stadium
runs
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
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].value_counts()
England 4
New Zealand 4
Pakistan 2
India 2
Zimbabwe 2
South Africa 1
Pakistan 1
Name: Team_2, dtype: int64
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_1'].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
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
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',
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
# Create a new DataFrame 'Pakistan' containing all rows from the filtered DataFrame
Pakistan = df2.iloc[:]
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
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
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 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
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
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].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
# Counting the occurrences of each value in the filtered DataFrame's 'Team_1' colum
value_counts = filtered_df['Team_1'].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
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
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',
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
# Create a new DataFrame 'New Zealand' containing all rows from the filtered DataFr
New_Zealand = df3.iloc[:]
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
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
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
New New
625 15/07/2022 Ireland won by 1 run The Village
Zealand Zealand
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].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
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_1'].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
# 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()
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()
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',
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
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_nz.values(), labels=win_percentages_wc_nz.keys(), autopc
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
# Create a new DataFrame 'England' containing all rows from the filtered DataFrame
England = df4.iloc[:]
New New
8 12/06/2015 England won by 13 runs Kennington Oval
Zealand Zealand
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
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
Dubai International
59 20/11/2015 Pakistan England England England won by 84 runs
Cricket 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
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
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
New
477 03/07/2019 England England won by 119 runs Riverside Ground
Zealand
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
521 01/08/2020 England Ireland England won by 4 wickets The Rose Bowl
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
613 17/06/2022 Netherlands England England won by 232 runs VRA Ground
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
# Counting the occurrences of each value in the filtered DataFrame's 'Team_2' colum
value_counts = filtered_df['Team_2'].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
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()
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
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages.values(), labels=win_percentages.keys(), autopct='%1.1f%%',
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
}
# Pie chart
plt.figure(figsize=(5, 5))
plt.pie(win_percentages_wc_eng.values(), labels=win_percentages_wc_eng.keys(), auto
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
Date 748
Out[137]:
Team_1 748
Team_2 748
Winner 748
Margin 748
Ground 748
dtype: int64
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
New New
8 12/06/2015 England won by 13 runs Kennington Oval
Zealand Zealand
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()
In [140… df_teams_2019
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
# Display the first few rows of the modified DataFrame using df_teams_2019.head().
df_teams_2019.head()
# 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
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
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
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()
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 [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]
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
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
India vs Australia
Winner: Australia
Bangladesh vs England
Winner: England
Afghanistan vs India
Winner: India
Afghanistan vs England
Winner: England
India vs Pakistan
Winner: Pakistan
Bangladesh vs India
Winner: India
Pakistan vs Australia
Winner: Australia
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
Netherlands vs Australia
Winner: Australia
Netherlands vs Bangladesh
Winner: Bangladesh
England vs India
Winner: India
Bangladesh vs Pakistan
Winner: Pakistan
Netherlands vs Afghanistan
Winner: Afghanistan
England vs Australia
Winner: Australia
Afghanistan vs Australia
Winner: Australia
Netherlands vs England
Winner: England
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
# 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
# Add the missing columns to the pred_set DataFrame and set their values to 0
for c in missing_cols2:
pred_set[c] = 0
# 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("")
Pakistan vs Australia
Winner: Australia
England vs India
Winner: 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