Cricket Prediction ML
Cricket Prediction ML
Royal Royal
2017- Sunrisers
0 1 2017 Hyderabad Challengers Challengers field no
04-05 Hyderabad
Bangalore Bangalore
Kolkata Kolkata
2017- Gujarat
2 3 2017 Rajkot Knight Knight field no
04-07 Lions
Riders Riders
Royal Royal
2017- Delhi
4 5 2017 Bangalore Challengers Challengers bat no
04-08 Daredevils
Bangalore Bangalore
Out[96]: CH Gayle 21
AB de Villiers 20
RG Sharma 17
MS Dhoni 17
DA Warner 17
YK Pathan 16
SR Watson 15
SK Raina 14
G Gambhir 13
AM Rahane 12
MEK Hussey 12
V Kohli 12
A Mishra 11
AD Russell 11
DR Smith 11
V Sehwag 11
JH Kallis 10
KA Pollard 10
AT Rayudu 9
SP Narine 9
SE Marsh 9
Harbhajan Singh 8
RA Jadeja 8
SR Tendulkar 8
UT Yadav 8
AC Gilchrist 7
RV Uthappa 7
Rashid Khan 7
SL Malinga 6
RR Pant 6
..
DL Chahar 1
Z Khan 1
KK Cooper 1
S Gill 1
TL Suman 1
Q de Kock 1
KMDN Kulasekara 1
NV Ojha 1
JJ Roy 1
RE Levi 1
DL Vettori 1
Imran Tahir 1
EJG Morgan 1
A Joseph 1
AC Voges 1
S Sreesanth 1
JDP Oram 1
J Archer 1
MJ Lumb 1
H Gurney 1
CR Brathwaite 1
M Ur Rahman 1
GD McGrath 1
SB Jakati 1
HH Gibbs 1
K Rabada 1
Mohammed Shami 1
CRD Fernando 1
M Kartik 1
A Singh 1
Name: player_of_match, Length: 226, dtype: int64
Out[97]: CH Gayle 21
AB de Villiers 20
RG Sharma 17
MS Dhoni 17
DA Warner 17
YK Pathan 16
SR Watson 15
SK Raina 14
G Gambhir 13
AM Rahane 12
Name: player_of_match, dtype: int64
Out[98]: CH Gayle 21
AB de Villiers 20
RG Sharma 17
MS Dhoni 17
DA Warner 17
Name: player_of_match, dtype: int64
In [99]: list(ipl['player_of_match'].value_counts()[0:5].keys())
Out[99]: ['CH Gayle', 'AB de Villiers', 'RG Sharma', 'MS Dhoni', 'DA Warner']
In [104… batting_first.head()
Royal Royal
2017- Sunrisers
0 1 2017 Hyderabad Challengers Challengers field
04-05 Hyderabad
Bangalore Bangalore
Royal Royal
2017- Delhi
4 5 2017 Bangalore Challengers Challengers bat
04-08 Daredevils
Bangalore Bangalore
Kolkata
2017- Sunrisers Sunrisers
13 14 2017 Kolkata Knight field
04-15 Hyderabad Hyderabad
Riders
plt.hist(batting_first['win_by_runs'])
plt.title('Distribution of Runs')
plt.xlabel('Runs')
plt.show()
In [107… #Creating barplot for Top 3 Teamsn Wins After Batting First
plt.figure(figsize=(6,5))
plt.bar(list(batting_first['winner'].value_counts()[0:3].keys()),list(batting_fi
plt.show()
In [109… #Extracting those Records Where A Team has Won After Batting Second
batting_second=ipl[ipl['win_by_wickets']!=0]
In [110… batting_second.head()
Rising
2017- Mumbai Rising Pune
1 2 2017 Pune Pune field nor
04-06 Indians Supergiant
Supergiant
Kolkata Kolkata
2017- Gujarat
2 3 2017 Rajkot Knight Knight field nor
04-07 Lions
Riders Riders
Rising
2017- Kings XI Kings XI
3 4 2017 Indore Pune field nor
04-08 Punjab Punjab
Supergiant
Kolkata
2017- Mumbai Mumbai
6 7 2017 Mumbai Knight field nor
04-09 Indians Indians
Riders
In [112… #finding out the frequency of no of wins w.r.t. each time after batting second
batting_second['winner'].value_counts()
In [113… #Making a bar plot for Top 3 teamsn with wins after batting second
In [114… plt.figure(figsize=(7,7))
plt.bar(list(batting_second['winner'].value_counts()[0:3].keys()),list(batting_s
plt.show()
Out[116]: 2013 76
2012 74
2011 73
2019 60
2018 60
2016 60
2014 60
2010 60
2017 59
2015 59
2008 58
2009 57
Name: season, dtype: int64
In [118… #Find out how many times a team has won the match after wining toss
import numpy as np
np.sum(ipl['toss_winner']==ipl['winner'])
Out[118]: 393
In [119… deliveries=pd.read_csv('deliveries.csv')
In [120… deliveries.head()
Royal
Sunrisers DA
0 1 1 Challengers 1 1 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
1 1 1 Challengers 1 2 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
2 1 1 Challengers 1 3 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
3 1 1 Challengers 1 4 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
4 1 1 Challengers 1 5 S Dhawan
Hyderabad Warner
Bangalore
5 rows × 21 columns
In [121… deliveries['match_id'].unique()
In [122… match_1=deliveries[deliveries['match_id']==1]
In [123… match_1.head()
Royal
Sunrisers DA
0 1 1 Challengers 1 1 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
1 1 1 Challengers 1 2 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
2 1 1 Challengers 1 3 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
3 1 1 Challengers 1 4 S Dhawan
Hyderabad Warner
Bangalore
Royal
Sunrisers DA
4 1 1 Challengers 1 5 S Dhawan
Hyderabad Warner
Bangalore
5 rows × 21 columns
In [124… match_1.shape
In [125… srh=match_1[match_1['inning']==1]
In [126… srh['batsman_runs'].value_counts()
Out[126]: 1 57
0 32
4 17
6 9
2 9
3 1
Name: batsman_runs, dtype: int64
In [127… srh['dismissal_kind'].value_counts()
Out[127]: caught 3
bowled 1
Name: dismissal_kind, dtype: int64
In [128… rcb=match_1[match_1['inning']==2]
In [129… rcb['batsman_runs'].value_counts()
Out[129]: 0 49
1 44
4 15
6 8
2 7
Name: batsman_runs, dtype: int64
In [130… rcb['dismissal_kind'].value_counts()
Out[130]: caught 6
run out 2
bowled 2
Name: dismissal_kind, dtype: int64