R: Web Scraping NBA Statistics

Posted on Dec 13, 2017

This is my second project. A project focused on web scraping and producing models and insights too viewers that they would not typically see or be able to extract from certain data upon first observation. I am passionate about sports and thought connecting data science to sports in this project would be very intriguing.

The technology industry has taken over every realm of society it seems like with little opposition. From the way people entertain ourselves with our smart phones and social media all the way to how business operate and how they sell and market their products and respective brands. It seems hand in hand with this takeover, Data Science has seen a profound boom in its prominence in its use and application today due to the benefits and new realizations that people have come to see through the various new models and new statistics formed by machine learning programs as well as analytics.

For this reason alone, sports has seen a dramatic increase in the use of analytics and various algorithms and programs too see what factors not looked at before can increase a teams chance of winning as well as the organization's chance at future success. I personally, am a avid sports fan who takes every chance he can get to discuss and learn more about people's favorite teams as well as their philosophies and opinions on what they think is most important or crucial in creating a successful team in any sport. In this project I focused on basketball and tried to find new little statistics that could be seen through their prevalence on successful teams as a factor crucial in order to win and be successful.Through scraping nba statistics from teamrankings.com from last season and engineering the data, I attempted to find new and improved ways that analytically can be shown to be crucial to winning championships and are apparent on top tier teams such as the Cavaliers and Warriors.

I did this by creating a scraper that scraped teamrankings.com for NBA statistics from last season. The categories I scraped were each teams Average 4th Quarter margin, Each teams average points from 3-pt FGs per game, each teams average Points in the Paint per Game, as well as each teams total points resulting from fast break opportunities. Upon scraping, the resulting csv files show for the 4 categories: each teams rank compared to the rest of the league, their average of that statistic for the season, the respective statistic from the previous game, average of that statistic over the last 3 games, as well as their averages both on the road as well as at home.

This is what the resulting csv file for total points in the paint per game:

I believe these statistics are some of the most important and crucial to success in basketball and hopefully some of my statistics, models and graphs can strengthen my assertion.

This graph shows the home and away averages for 4th quarter margins of each team.

Unfortunately for me in wanting some results with strong correlations, none can strongly be made in terms of winning the 4th quarter resulting in championships. 7 of the top 10 teams in this category did make the playoffs with the champion Warriors coming in at 6, but their opponent in last years finals, the Cavaliers were 27th out of 30 teams in the category but seemed to be doing just fine in coasting to their 3rd straight finals appearance. For one that is familiar with basketball, know from the perspective that basketball is a game of 4 quarters, good teams may already have handled lesser competition in 3 quarters by more than 20 points for example and are not affected by their losing margin in the 4th because it does not pose any significance to the end outcome of the game. In terms of further research one could look to see games that go into the fourth quarter with a team trailing by 5 or less points as a more effective way of analyzing performance in the 4th because that involves the clutch factor.

When looking at FastBreak Points per game I thought it would be interesting to see teams change in averages from the 2015 season to the 2016 season.

Here the chart shows each teams averages side by side:

17 teams improved from the season before while 13 did not. Of the 3 of the final 4 teams from the NBA 2016 Season (Cavs, Warriors, Spurs, Celtics) only the Celtics decreased in their average fast break points per game. Both six seeds (OKC and Bucks) and seven seeds(Pacers and Griz) from each conference decreased in their averages from the previous season along with one 5 seed (Hawks), 3 seed(Rockets), and 4 seed(Wizards). None of these teams looking at statistics as well as the overall eye test had a chance at winning the championship last season and does show the increasing value and importance of teams improving their fast break scoring. The champion Warriors have led the statistics the past 3 seasons, and barring the 3-1 collapse, have produced 3 championship seasons.

Further research wise when looking at this project from a big picture is that data science will always prove beneficial and vital in improving quality of teams and athlete's performance in regards to sports. And it will only grow because even through simple models such as these one can see that the 4th Quarter margin does not mean as much as the amount of fast break points a team is producing per game. Little things like this and the little edge that teams, coaches, scouts, and executives are all looking for and crave can and will all be produced through data science. With it providing a constantly new and innovative way to look at what was perceived in the past as bland and concrete statistics in a more complex and alternative way.

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp