<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/predicting-the-baseball-hall-of-fame/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.nycdatascience.com/student-works/predicting-baseball-hall-fame/"> R – NYC Data Science Academy Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h4>Intro</h4>
<p><span>The Great Bambino. The Big Unit. Joltin’ Joe. Henry Rowengartner. If you’re familiar with the sport of baseball, you might recognize some of these names from real life or the movies. Since baseball has been engrained in the fabric of America for almost 200 years, and since it is my favorite sport, I decided that I thought it might be fun to take a look back at some of the best players to ever play the game, and see how modern day players stack up against them.</span></p>
<h4>The Motivation</h4>
<p><span>Sports analytics have progressed drastically in recent years, and with the wealth of data available for Major League Baseball, many teams are employing analytics departments to extract value out of statistics. I decided to scrape the hall of fame players on baseball-reference.com to investigate these statistics and determine how good a player has to be in order to be inducted into the hall of fame. Additionally, I took a sample of data from players that have played since 1989 in order to predict whether or not they might be eligible to make the hall of fame.</span></p>
<h4>Extracting the Data</h4>
<p><span>The parent URL I used to extract Hall of Fame player statistics was on <a target="_blank" rel="nofollow" href="http://www.baseball-reference.com/awards/hof.shtml">Baseball Reference</a>, a baseball database that has all the baseball statistics one could ever want. I had to write two separate spiders to take into account the different statistics used to measure a batter’s statistical output and a pitcher’s statistical output. All in all, there are 163 batters in the baseball hall of fame, which translates to a file of roughly 3500 rows (includes all their seasons played). There are 77 pitchers in the hall of fame, which translates to a file of about 1600 rows (includes all their seasons played). The data for more recent players was downloaded and filtered to include only batters that had over 500 plate appearances per year, and only pitchers who pitched over 150 innings per year in order to normalize numbers.</span></p>
<h4>Insights</h4>
<p><span>First, I took a look at batters. I wanted to get a sense of the distribution of number home runs are hit per season for hall of fame batters, as well as number of hits per season. The histograms look like this:</span></p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.16.49-PM.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="" class="wp-image-21889" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.16.49-PM-1024x699.png?w=450" data-recalc-dims="1"></a></p>
<p> </p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.15.26-PM.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="" class="wp-image-21890" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.15.26-PM-1024x683.png?w=450" data-recalc-dims="1"></a></p>
<p> </p>
<p><span>Hitting a high number of home runs don’t appear to be a huge indication of making it to the hall of fame, although it probably doesn’t hurt. We do see that on average, there are roughly 160 games hit per year most frequently, which translates to about one hit per game. A batter that bats .300 for a season, or fails to get a hit 70% of their at bats, is considered a great hitter. I also plotted the total number of strikeouts against number of walks, and noticed that many Hall of Fame hitters had tremendous plate discipline (walks were greated than strikeouts).</span></p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.20.32-PM.png"><img sizes="(max-width: 713px) 100vw, 713px" alt="" class="wp-image-21891" src="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.20.32-PM.png?w=450" data-recalc-dims="1"></a></p>
<p> </p>
<p><span>Finally, I plotted the batter based on OPS, or On Base Percentage plus Slugging Percentage, a general statistic to measure the overall value of a player. Suffice to say, I was not surprised to see Babe Ruth at the top of that list.</span></p>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.21.56-PM.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="" class="wp-image-21893" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-7.21.56-PM-1024x639.png?w=450" data-recalc-dims="1"></a></p>
<p><span>For pitchers, I mostly wanted to see their performance in terms of outcomes they could control, which are home runs allowed, strikeouts, and walks. I plotted the strikeouts per nine innings against the walks per nine innings. We see an interesting linear trend, where the higher the strikeout numbers, the higher the walks. This could say something about the pitcher’s ability to spin and curve the baseball in order to deceive hitters, which might lead to a lot of strikeouts but also less control.</span></p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-8.07.26-PM.png"><img sizes="(max-width: 528px) 100vw, 528px" alt="" class="wp-image-21894" src="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-8.07.26-PM.png?w=450" data-recalc-dims="1"></a></p>
<p> </p>
<p><span>In order to measure overall value of a pitcher, I measured their FIP, or fielding independent pitching. This takes into account number of home runs allowed, number of strikeouts, number of walks, and a constant number to normalize the statistic. The lower the FIP, the better.</span></p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-8.06.04-PM.png"><img sizes="(max-width: 1024px) 100vw, 1024px" alt="" class="wp-image-21896" src="https://i0.wp.com/blog.nycdatascience.com/wp-content/uploads/2017/05/Screen-Shot-2017-05-07-at-8.06.04-PM-1024x630.png?w=450" data-recalc-dims="1"></a></p>
<p><span>According to FIP, Big Ed Walsh is the best pitchers in the hall of fame, followed by the more contemporary Pedro Martinez.</span></p>
<p> </p>
<h4>Predicting Hall of Famers</h4>
<p><span>Since I had the hall of fame statistics, I figure that I could use these as a baseline and try to fit a logistic regression model that would take data for more recent players and predict whether or not they would would make the hall of fame. I combined my hall of fame data with the separate subset of more recent players, and then used cross-validation to train the model. Then, I predicted and tested it on the test set.</span></p>
<p><span>For predicting players, I used backwards selection, and tested the correlation between each variable to make sure there was as little multicollinearity as possible. I then created a binary variable to categorized players that are in the hall of fame versus those who aren’t. For batters, my best model had hits per season as the most significant predictor (the higher the better), followed by overall strikeout rate (the lower the better). The accuracy of this model was 97%, which beat the baseline of 83% by a wide margin. The accuracy was very high and variance was very low, and I definitely could have used more data to obtain a better model.</span></p>
<p><span>For pitchers, my best predictor was walks and hits per inning (the fewer the better), and home runs per 9 innings (fewer the better). FIP also was included in the model, though including it might have not been necessary, as it is essentially a total measure of home runs, walks, and strikeouts. The accuracy of this model was 95%, which beat the baseline model of 90%. Again, this was highly biased due to lack of data and cross-validating my model.</span></p>
<h4>Further Improvements</h4>
<p>There are a few things worth noting for the model:</p>
<ul>
<li>I only used one training set and one test set, and could have used a higher K value to cross-validate the model.</li>
<li>The data is highly biased, as I could have grabbed more data for non hall of fame players, but did not due to time constraints.</li>
<li>We could use more advanced statistics to more accurately predict, but I used the data from the statistics I scraped.</li>
</ul>
<p> </p>
<p>With more statistics, we should be able to create a model that will knock it out of the park (I’m sorry).</p>
<p>The post <a target="_blank" rel="nofollow" href="http://blog.nycdatascience.com/student-works/predicting-baseball-hall-fame/">Predicting the Baseball Hall of Fame</a> appeared first on <a target="_blank" rel="nofollow" href="http://blog.nycdatascience.com/">NYC Data Science Academy Blog</a>.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.nycdatascience.com/student-works/predicting-baseball-hall-fame/"> R – NYC Data Science Academy Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/ESnp3MA_OXw"></a></div>