Blockbuster Entry of Data Science and Analytics into the Sports World.
Tags: Sports Analytics, Data Analysis, Regression, Data Science, Machine Learning

Prediction of the number of wins Oakland Athletics required to enter into the Playoffs of American Baseball League for the 2002 season using Linear and Nonlinear Machine Learning Models.

Roadmap:

What’s this about

What’s the take from this

What does the dataset talk about

- Ok, let’s tweak it!

- Ok, let’s tweak it! Let’s get some numbers from these Machine Learning models

- Extreme Gradient Boosting (XGB)

- Linear Regression

- Extreme Gradient Boosting (XGB) - Linear Regression That’s a wrap

1. What’s this about

Beane (Oakland A’s general manager) and DePodesta (analytics strategist) are utter daredevils that they decided to think out of the box and found value in data and were the first managers ever to make data-driven decisions from recruiting the club players to building game strategies. This gutsy move made the shoestring-budget team win 20 consecutive games in the 2002 Major League Baseball season, setting an American League record. The team finished first in the American League West with a staggering season record of 103 wins and 59 losses.

2. What’s the take from this

After losing key players from the team, with wafer-thin ice of a team budget, molding 9 new recruits to the team, it was clearly not a cakewalk for Beane to have his team enter the playoffs. He tackled this challenge with the might of data. Without further ado, let’s hear from the data on how it set their path to glory by winning 101 games by analyzing the game stats for the years from 1962–2001.

3. What does the Dataset talk about

This data set contains a set of variables that Beane and DePodesta focused heavily on. They determined that stats like on-base percentage (OBP) and slugging percentage (SLG) were very important when it came to scoring runs, however they were largely undervalued by most scouts at the time. This translated to a gold mine for Beane and DePodesta. Since these players weren’t being looked at by other teams, they could recruit these players on a small budget. The variables are as follows:

Team

League

Year

Runs Scored (RS)

Runs Allowed (RA)

Wins (W)

On-Base Percentage (OBP)

Slugging Percentage (SLG)

Batting Average (BA)

Playoffs (binary)

RankSeason

RankPlayoffs

Games Played (G)

Opponent On-Base Percentage (OOBP)

Opponent Slugging Percentage (OSLG)

This dataset can be found here (source: Kaggle)

Okay, let’s tweak it!

In this precious time, we’re about to see the required number of wins that were calculated by the ML models for the team to enter into the Playoffs. So, the target variable from the obtained data is W (Wins), and to find out the independent variables, let’s take help from these steps:

Import these libraries

Python libraries and packages necessary for this case study

3.2 Exploring the dataset and tweaks

Reading the data and getting the datatype information

The categorical variables/columns are Team and League. Other columns are all continuous (numerical).

Let’s use just some of the variables

Although there are 14 independent variables, not every variable will provide information or any significance in predicting the number of Wins (target variable). So, this colorful plot, the heatmap will help us in narrowing down the significant features with the aid of correlation with the target variable.

Correlation plot

The variables that help in deciding the number of wins (W) are RS (Runs scored), RA (Runs Against), OBP (On-Base Percentage — how frequently a batter reaches the base), and SLG (Slugging percentage — batting productivity of a player). OOBP & OSLG are of course the metrics of the opponent team, so the higher it is for them, your winning chances get tough, therefore you see a negative sign with these variables against the W.

Multicollinearity is observed, therefore eliminating a few features is advised here. OBP & SLG are highly correlated with RS, whereas OOBP & OSLG are highly correlated with RA, they provide the same information, therefore RA & RS can be dropped.

Getting the data on python & initial steps:

Getting the data on python

What to do with Null values

Okay, so there are some records with empty cells. Right, Machine Models are so adamant that they throw errors if they’re fed with Null values, so some sort of imputation is required.

Let’s impute them using one of the popular yet advanced methods, Iterative Imputer. To read about this interesting method that uses the Linear Regression algorithm, click here.

Thanks to the imputation algorithm, our data is now ready to enter the labyrinth of ML world.

4. Let’s get some numbers from these Machine Learning models

Two possible routes lie ahead, let us take the ghats first, where decision trees (nonlinear model) are the cornerstones. Later, let’s see how close a linear model can get to the 101 wins.

Extreme Gradient Boosting (XGB).

First, let’s allocate what’s about to train and test our model.

Training — Target & Independent variables

Let’s get the best hyperparameters to train our model.

GridSearchCV algorithm helps for this purpose

Best Parameters for XGB Model

Given Test data, holds Oakland Athletics Statistics in 2001 before the playoffs

Data for model prediction

Fingers crossed! (Prediction)

Plugging in the testing data into the XGBRegressor model with the hyperparameters obtained from GridSearchCV

Prediction Result

Mr.DePodesta from the movie Moneyball, Image Source: wordpress.com

Well, Mr. DePodesta should be impressed with this result.

Now, let’s see what a linear model would predict.

2. LinearRegression

Passing the training and testing data.

5. That’s a wrap

Kudos to Mr. Paul DePodesta and Mr. Billy Bean for their astonishing work in setting a record in the league and for introducing Statistical Data Science and Analysis into the sports field.

To sum up, the numbers are favoring the nonlinear model — XGBRegressor as the prediction is closer by 0.06 to 101 whereas, the LinearRegression model is 1.87 above 101.

Link to the Dataset and Problem Description : https://www.kaggle.com/wduckett/moneyball-mlb-stats-19622012