# GooglyPlusPlus: Computing T20 player’s Win Probability Contribution

**R – Giga thoughts …**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In this post, I compute each batsman’s or bowler’s **Win Probability Contribution (WPC) **in a T20 match. This metric captures by how much the player (batsman or bowler) changed/impacted the Win Probability of the T20 match. For this computation I use my machine learning models, I had created earlier, which predicts the ball-by-ball win probability as the T20 match progresses through the 2 innings of the match.

In the picture snippet below, you can see how the win probability changes ball-by-ball for each batsman for a T20 match between CSK vs LSG- 31 Mar 2022

In my previous posts I had created several Machine Learning models. In order to compute the player’s Win Probability contribution in this post, I have used the following ML models

- Logistic Regression model – glmnet : accuracy – 0.728 and roc_auc – 0.81 – Boosting Win Probability accuracy with player embeddings
- Deep Learning model – DL – accuracy – 0.8639 and roc_auc – 0.946 – GooglyPlusPlus: Win Probability using Deep Learning and player embeddings

The batsman’s or bowler’s win probability contribution changes ball-by=ball. The player’s contribution is calculated as the difference in win probability when the batsman faces the 1st ball in his innings and the last ball either when is out or the innings comes to an end. If the difference is +ve the the player has had a positive impact, and likewise for negative contribution. Similarly, for a bowler, it is the win probability when he/she comes into bowl till, the last delivery he/she bowls

**Note**: The Win Probability Contribution does not have any relation to the how much runs or at what strike rate the batsman scored the runs. Rather the model computes different win probability for each player, based on his/her embedding, the ball in the innings and six other feature vectors like runs, run rate, runsMomentum etc. These values change for every ball as seen in the table above. Also, this is not continuous. The 2 ML models determine the Win Probability for a specific player, ball and the context in the match.

This metric is similar to **Win Probability Added (WPA)** used in Sabermetrics for baseball. Here is the definition of WPA from Fangraphs “*Win Probability Added (WPA) captures the change in Win Expectancy from one plate appearance to the next and credits or debits the player based on how much their action increased their team’s odds of winning*.” This article in Fangraphs explains in detail how this computation is done.

In this post I have added 4 new function to my R package yorkr.

- batsmanWinProbLR – batsman’s win probability contribution based on glmnet (Logistic Regression)
- bowlerWinProbLR – bowler’s win probability contribution based on glmnet (Logistic Regression)
- batsmanWinProbDL – batsman’s win probability contribution based on Deep Learning Model
- bowlerWinProbDL – bowlerWinProbLR – bowler’s win probability contribution based on Deep Learning

Hence there are 4 additional features in GooglyPlusPlus based on the above 4 functions. In addition I have also updated

-winProbLR (overLap) function to include the names of batsman when they come to bat and when they get out or the innings comes to an end, based on Logistic Regression

-winProbDL(overLap) function to include the names of batsman when they come to bat and when they get out based on Deep Learning

Hence there are 6 new features in this version of GooglyPlusPlus.

**Note**: All these new 6 features are available for all 9 formats of T20 in GooglyPlusPlus namely

a) IPL b) BBL c) NTB d) PSL e) Intl, T20 (men) f) Intl. T20 (women) g) WBB h) CSL i) SSM

Check out the latest version of GooglyPlusPlus at gpp2023-2

Note: The data for GooglyPlusPlus comes from Cricsheet and the Shiny app is based on my R package yorkr

A) **Chennai SuperKings vs Delhi Capitals – 04 Oct 2021**

To understand Win Probability Contribution better let us look at Chennai Super Kings vs Delhi Capitals match on 04 Oct 2021

This was closely fought match with fortunes swinging wildly. If we take a look at the Worm wicket chart of this match

**a) Worm Wicket chart** –

**CSK vs DC – 04 Oct 2021**

Delhi Capitals finally win the match

b) **Win Probability Logistic Regression (side-by-side) – CSK vs DC – 4 Oct 2021**

Plotting how win probability changes over the course of the match using Logistic Regression Model

In this match Delhi Capitals won. The batting scorecard of Delhi Capitals

**c) Batting Scorecard of Delhi Capitals – CSK vs DC – 4 Oct 2021**

d) **Win Probability Logistic Regression (Overlapping) – CSK vs DC – 4 Oct 2021**

The Win Probability LR (overlapping) shows the probability function of both teams superimposed over one another. The plot includes when a batsman came into to play and when he got out. This is for both teams. This looks a little noisy, but there is a way to selectively display the change in Win Probability for each team. This can be done , by clicking the 3 arrows (orange or blue) from top to bottom. First double-click the team CSK or DC, then click the next 2 items (blue,red or black,grey) Sorry the legends don’t match the colors!

Below we can see how the win probability changed for Delhi Capitals during their innings, as batsmen came into to play. See below

**e)** **Batsman Win Probability contribution:DC – CSK vs DC – 4 Oct 2021**

Computing the individual batsman’s Win Contribution and plotting we have. Hetmeyer has a higher Win Probability contribution than Shikhar Dhawan depsite scoring fewer runs

**f**) **Bowler’s Win Probability contribution :CSK – CSK vs DC – 4 Oct 2021**

We can also check the Win Probability of the bowlers. So for e.g the CSK bowlers and which bowlers had the most impact. Moeen Ali has the least impact in this match

**B) Intl. T20 (men) Australia vs India – 25 Sep 2022**

**a) Worm wicket chart – Australia vs India – 25 Sep 2022**

This was another close match in which India won with the penultimate ball

**b) Win Probability based on Deep Learning model (side-by-side) –** **Australia vs India – 25 Sep 2022**

**c) Win Probability based on Deep Learning model (overlapping) –** **Australia vs India – 25 Sep 2022**

The plot below shows how the Win Probability of the teams varied across the 20 overs. The 2 Win Probability distributions are superimposed over each other

**d) Batsman Win Probability Contribution : India** – **Australia vs India – 25 Sep 2022**

Selectively choosing the India Win Probability plot by double-clicking legend ‘India’ on the right , followed by single click of black, grey legend we have

We see that Kohli, Suryakumar Yadav have good contribution to the Win Probability

**e) Plotting the Runs vs Strike Rate:India – ** **Australia vs India – 25 Sep 2022**

**f) Batsman’s Win Probability Contribution-** **Australia vs India – 25 Sep 2022**

Finally plotting the Batsman’s Win Probability Contribution

Interestingly, Kohli has a greater Win Probability Contribution than SKY, though SKY scored more runs at a better strike rate. As mentioned above, the Win Probability is context dependent and also depends on past performances of the player (batsman, bowler)

Finally let us look at

**C) India vs England Intll T20 Women (11 July 2021)**

**a) Worm wicket chart – India vs England Intl. T20 Women (11 July 2021)**

India won this T20 match by 8 runs

**b) Win Probability using the Logistic Regression Model –** **India vs England Intl. T20 Women (11 July 2021)**

**c) Win Probability with the DL model –** **India vs England Intl. T20 Women (11 July 2021)**

**d) Bowler Win Probability Contribution with the LR model** **–** **India vs England Intl. T20 Women (11 July 2021)**

**e) Bowler Win Contribution with the DL model** **–** **India vs England Intl. T20 Women (11 July 2021)**

Go ahead and try out the latest version of GooglyPlusPlus

Also see my other posts

- Deep Learning from first principles in Python, R and Octave – Part 8
- A method to crowd source pothole marking on (Indian) roads
- Big Data 7: yorkr waltzes with Apache NiFi
- Practical Machine Learning with R and Python – Part 6
- Introducing cricpy:A python package to analyze performances of cricketers
- Revisiting World Bank data analysis with WDI and gVisMotionChart
- Literacy in India – A deepR dive
- Cricketr learns new tricks : Performs fine-grained analysis of players
- Presentation on “Intelligent Networks, CAMEL protocol, services & applications”
- Adventures in LogParser, HTA and charts

To see all posts click Index of posts

**leave a comment**for the author, please follow the link and comment on their blog:

**R – Giga thoughts …**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.