Informed choices through Machine Learning – Analyzing Kohli, Tendulkar and Dravid


Having just completed the highly stimulating & inspiring Stanford’s Machine Learning course at Coursera, by the incomparable Professor Andrew Ng I wanted to give my newly acquired knowledge a try. As a start, I decided to try my hand at  analyzing one of India’s fastest growing stars, namely Virat Kohli . For the data on Virat Kohli I used the ‘Statistics database’ at ESPN Cricinfo. To make matters more interesting,  I also pulled data on the iconic  Sachin Tendulkar and the Mr. Dependable,  Rahul Dravid.

(Also do check out my R package cricketr  Introducing cricketr! : An R package to analyze performances of cricketers and my interactive Shiny app implementation using my R package cricketr  – Sixer – R package cricketr’s new Shiny avatar )

Take a look at my book with all my articles related to cricket –  Cricket analytics with cricketr!!!. The book is also available in paperback and kindle versions at Amazon  which has, by the way,  better formatting!

Based on the data of these batsmen I perform some predictions with the help of machine learning algorithms. That I have a proclivity for prediction, is not surprising, considering the fact that my Dad was an astrologer who had reasonable success at this esoteric art. While he would be concerned with planetary positions, about Rahu in the 7th house being in the malefic etc., I on the other hand focus my  predictions on multivariate regression analysis and K-Means. The first part of my post gives the results of my analysis and some predictions for Kohli, Tendulkar and Dravid.

The second part of the post contains a brief outline of the implementation and not the actual details of implementation. This is ensure that I don’t violate Coursera’s Machine Learning’ Honor Code.

This code, data used and the output obtained  can be accessed at GitHub at ml-cricket-analysis

Analysis and prediction of Kohli, Tendulkar and Dravid with Machine Learning As mentioned above, I pulled the data for the 3 cricketers Virat Kohli, Sachin Tendulkar and Rahul Dravid. The data taken from Cricinfo database for the 3 batsman is based on  the following assumptions

  • Only ‘Minutes at Crease’ and ‘Balls Faced’ were taken as features against the output variable ‘Runs scored’
  • Only test matches were taken. This included both test ‘at home’ and ‘away tests’
  • The data was cleaned to remove any DNB (did not bat) values
  • No extra weightage was given to ‘not out’. So if Kohli made ‘28*’ 28 not out, this was taken to be 28 runs

 Regression Analysis for Virat Kohli There are 51 data points for Virat Kohli regarding Tests played. The data for Kohli is displayed as a 3D scatter plot where x-axis is ‘minutes’ and y-axis is ‘balls faced’. The vertical z-axis is the ‘runs scored’. Multivariate regression analysis was performed to find the best fitting plane for the runs scored based on the selected features of ‘minutes’ and ‘balls faced’.

This is based on minimizing the cost function and then performing gradient descent for 400 iterations to check for convergence. This plane is shown as the 3-D plane that provides the best fit for the data points for Kohli. The diagram below shows the prediction plane of  expected runs for a combination of ‘minutes at crease’ and ‘balls faced’. Here are 2 such plots for Virat Kohli. kohliAnother view of the prediction plane kohli-1 Prediction for Kohli I have also computed the predicted runs that will be scored by Kohli for different combinations of ‘minutes at crease’ and ‘balls faced’. As an example, from the table below, we can see that the predicted runs for Kohli   after being in the crease for 110 minutes  and facing 135 balls is 54 runs. kohli-score Regression analysis for Sachin Tendulkar There was a lot more data on Tendulkar and I was able to dump close to 329 data points. As before the ‘minutes at crease’, ‘balls faced’ vs ‘runs scored’ were plotted as a 3D scatter plot. The prediction plane is calculated using gradient descent and is shown as a plane in the diagram below srt Another view of this below srt-1 Predicted runs for Tendulkar The table below gives the predicted runs for Tendulkar for a combination of  time at crease and balls faced.  Hence,  Tendulkar will score 57 runs in 110 minutes after  facing 135 deliveries srt-score Regression Analysis for Rahul Dravid The same was done for ‘the Wall’ Dravid. The prediction plane is below dravid dravid-1 Predicted runs for Dravid The predicted runs for Dravid for combinations of batting time and balls faced is included below.  The predicted runs for Dravid after facing 135 deliveries in 110 minutes is 44. dravid-scoreFurther analysis While the ‘prediction plane’ was useful,  it somehow does not give a clear picture of how effective each batsman is. Clearly the 3D plots show at least 3 clusters for each batsman. For all batsmen, the clustering is densest near the origin, become less dense towards the middle and sparse on the other end. This is an indication during which session during their innings the batsman is most prone to get out. So I decided to perform K-Means clustering on the data for the 3 batsman. This gives the 3 general tendencies  for each batsman. The output is included below

K-Means for Virat The K-Means for Virat Kohli indicate the follow

Centroids found 255.000000 104.478261 19.900000
Centroids found 194.000000 80.000000 15.650000
Centroids found 103.000000 38.739130 7.000000

Analysis of Virat Kohli’s batting tendency
Kohli has a 45.098 percent tendency to bat for 104 minutes,  face 80 balls and score 38 runs
Kohli has a 39.216 percent tendency to bat for 19 minutes, face 15 balls and score 7 runs
Kohli has a 15.686 percent tendency to bat for 255 minutes, face 194 balls and score 103 runs

The computation of this included in the diagram below

kohli-kmeans

K-means for Sachin Tendulkar

The K-Means for Sachin Tendulkar indicate the following

Centroids found 166.132530 353.092593 43.748691
Centroids found 121.421687 250.666667 30.486911
Centroids found 65.180723 138.740741 15.748691

Analysis of Sachin Tendulkar’s performance

Tendulkar has a 58.232 percent tendency to bat for 43 minutes, face 30 balls and score 15 runs
Tendulkar has a 25.305 percent tendency to bat for 166 minutes, face 121 balls and score 65 runs
Tendulkar has a 16.463 percent tendency to bat for 353 minutes, face 250 balls and score 138 runs
srt-kmeans K-Means for Rahul Dravid

Centroids found 191.836364 409.000000 50.506024
Centroids found 137.381818 290.692308 34.493976
Centroids found 56.945455 131.500000 13.445783

Analysis of Rahul Dravid’s performance
Dravid has a 50.610 percent tendency to bat for 50 minutes,  face 34 balls and score 13 runs
Dravid has a 33.537 percent tendency to bat for 191 minutes,  face 137 balls and score 56 runs
Dravid has a 15.854 percent tendency to bat for 409 minutes, face 290 balls and score 131 runs
dravid-kmeans Some implementation details The entire analysis and coding was done with Octave 3.2.4. I have included the outline of the code for performing the multivariate regression. In essence the pseudo code for this

  1. Read the batsman data (Minutes, balls faced versus Runs scored)
  2. Calculate the cost
  3. Perform Gradient descent

The cost was plotted against the number of iterations to ensure convergence while performing gradient descent convergence-kohli Plot the 3-D plane that best fits the data
The outline of this code, data used and the output obtained  can be accessed at GitHub at ml-cricket-analysis

Conclusion: Comparing the results from the K-Means Tendulkar has around 48% to make a score greater than 60
Tendulkar has a 25.305 percent tendency to bat for 166 minutes, face 121 balls and score 65 runs
Tendulkar has a 16.463 percent tendency to bat for 353 minutes, face 250 balls and score 138 runs

And Dravid has a similar 48% tendency to score greater than 56 runs
Dravid has a 33.537 percent tendency to bat for 191 minutes,  face 137 balls and score 56 runs
Dravid has a 15.854 percent tendency to bat for 409 minutes, face 290 balls and score 131 runs

Kohli has around 45% to score greater than 38 runs
Kohli has a 45.098 percent tendency to bat for 104 minutes,  face 80 balls and score 38 runs

Also Kohli has a lesser percentage to score lower runs as against the other two
Kohli has a 39.216 percent tendency to bat for 19 minutes, face 15 balls and score 7 runs

The results must be looked in proper perspective as Kohli is just starting his career while the other 2 are veterans. Kohli has a long way to go and I am certain that he will blaze a trail of glory in the years to come!

Watch this space!

Also see

1.Introducing cricketr! : An R package to analyze performances of cricketers
2.Informed choices with Machine Learning 2 – Pitting together Kumble, Kapil and Chandra
3. Analyzing cricket’s batting legends – Through the mirage with R
4. What’s up Watson? Using IBM Watson’s QAAPI with Bluemix, NodeExpress – Part 1
5. Bend it like Bluemix, MongoDB with autoscaling – Part 1

Advertisements

39 thoughts on “Informed choices through Machine Learning – Analyzing Kohli, Tendulkar and Dravid

  1. Dang TV utterly fascinating to put to use something that you just learned. Very impressive. I’d love to see the same schema applied to say
    manufacturing jobs across say TN, Maharashtra and Gujarat (tons of raw data available from Economic survey (NSSO and other sources) – happy to share sources and some reading 🙂
    human development index, girl child or infant mortality rates across the same three states

    Keep ’em coming!

  2. Pingback: Informed choices through Machine Learning-2: Pitting together Kumble, Kapil, Chandra | Giga thoughts …

  3. Pingback: Analyzing cricket’s batting legends – Through the mirage with R | Giga thoughts …

  4. Pingback: Masters of Spin: Unraveling the web with R | Giga thoughts …

  5. Pingback: What’s up Watson? Using IBM Watson’s QAAPI with Bluemix, NodeExpress – Part 1 | Giga thoughts …

  6. Pingback: Re-working the Lucy Richardson algorithm in OpenCV | Giga thoughts …

  7. Pingback: Hand detection through Haartraining: A hands-on approach | Giga thoughts …

  8. Pingback: Experiments with deblurring using OpenCV | Giga thoughts …

  9. Pingback: De-blurring revisited with Wiener filter using OpenCV | Giga thoughts …

  10. Pingback: Deblurring with OpenCV: Weiner filter reloaded | Giga thoughts …

  11. Pingback: Simplifying ML: Impact of degree of polynomial degree on bias & variance and other insights | Giga thoughts …

  12. Pingback: Mirror, mirror … the best batsman of them all? | Giga thoughts …

  13. Pingback: Thinking Web Scale-1: Map-Reduce – Bring compute to data | Giga thoughts …

  14. Pingback: TWS-4: Gossip protocol: Epidemics and rumors to the rescue | Giga thoughts …

  15. Pingback: Into the Telecom vortex | Giga thoughts …

  16. Pingback: Installing and using OpenCV with Visual Studio 2010 express | Giga thoughts …

  17. Pingback: Google’s Page Rank: Predicting the movements of a random web walker | Giga thoughts …

  18. Pingback: The common alphabet of programming languages | Giga thoughts …

  19. Pingback: The mind of a programmer | Giga thoughts …

  20. Pingback: How to program – Some essential tips | Giga thoughts …

  21. Pingback: Programming Zen and now – Some essential tips-2 | Giga thoughts …

  22. Pingback: Introducing cricketr! : A R package to analyze performances of cricketers | Giga thoughts …

  23. Pingback: Taking cricketr for a spin – Part 1 | Giga thoughts …

  24. Pingback: cricketr digs the Ashes! | Giga thoughts …

  25. Pingback: cricketr plays the ODIs! | Giga thoughts …

  26. Pingback: cricketr adapts to the Twenty20 International! | Giga thoughts …

  27. Pingback: Natural language processing: What would Shakespeare say? | Giga thoughts …

  28. Pingback: Revisiting crimes against women in India | Giga thoughts …

  29. Pingback: Literacy in India – A deepR dive | Giga thoughts …

  30. Pingback: Sixer – R package cricketr’s new avatar | Giga thoughts …

  31. Pingback: Simplifying Machine Learning algorithms – Part 1 | Giga thoughts …

  32. Pingback: The making of cricket package yorkr – Part 1 | Giga thoughts …

  33. Pingback: Re-introducing cricketr! : An R package to analyze performances of cricketers | Giga thoughts …

  34. Pingback: Data Analytics in Cricket | Analytic Guru

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s