Using Data to Investigate NBA Shot

Posted on May 1, 2017
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.
Image from:

The Data Set:

The goal of this project was to investigate NBA shot data to better understand what variables affect shot accuracy and shot selection.    The data set contained approximately 125,000 observations, with each observation corresponding to a shot that was taken during a game from the 2014-2015 NBA regular season.  For each observation, approximately 20 different variables were tracked, including shooter's distance to the basket, distance from the shooter to the nearest defender, and much more.  The data was recorded via SportVU technology, originally scraped from NBA Stats, and posted to Kaggle.

Accuracy vs. Shot Distance:

The first feature of the data set that I investigated was how shot accuracy varied with shot distance (1-dimensional).  After plotting mean shot accuracy versus shot distance (given to the tenth of a foot in each observation), we notice an interesting feature in the graph:

Using Data to Investigate NBA Shot


The notable feature in the above graph is indicated by the yellow line:  While accuracy among NBA players tends to generally decrease with shot distance, between approximately 10 to 20 feet,  accuracy is roughly constant.   One might naïvely expect that accuracy would be a strictly decreasing function of distance, reasoning that farther shots are strictly less likely to be made than closer shots (all else equal).   So why isn't accuracy significantly decreasing as shooters get farther from the hoop between the interval of 10 to 20 feet?  Certainly many factors could be responsible, but to list a few possibilities:

  • Players practice free-throws (15 feet away from hoop) more frequently than other shots, thus they're more accurate from nearby distances.
  • Defenders stay close to the basket, and guard their opponents differently depending on how close the opponent is from the basket--thus increasing the difficultly of closer shots (and the effects roughly balance out between 10-20 feet).
  • Our initial intuition is wrong that farther shots are always more difficult, and the above graph depicts the general relationship between shooter accuracy and distance.  (We could certainly test this in a controlled setting without defenders.)

Of the above hypotheses, the second is the easiest to test via the data set.   We can do this by plotting the graph of how distance from the shooter to the nearest defender varies with shot distance:


It does, in fact, appear that within this 10-20 foot range that average closest defender distance increases as shot distance increases.  Perhaps this can at least partially explain why shooting accuracy remains roughly constant within this range (closer shots are easier but more contested, longer shots are more difficult but less contested,  and within the 10-20 foot range these effects essentially balance out with respect to accuracy).

Accuracy and Distance

In order to test this hypothesis more directly, let's look at how shooting accuracy varies with distance, while keeping the distance from the shooter to the nearest defender ("Closest Defender Distance") constant.  As the latter quantity was also given in increments of a tenth of a foot, it was appropriate to aggregate the data via 1 foot intervals in order to address sparseness.

Using Data to Investigate NBA Shot

We can notice that along most rows (where Closest Defender Distance is ~ constant) we see a more consistent decrease in accuracy within the 10-20 foot range, suggesting that indeed defender distance was at least partially responsible for the trend observed in the first graph.  Of course to make more definitive conclusions we'd need to account for other relevant variables (shooter/defender height, for example) and perform appropriate statistical analyses.

Data on Accuracy vs. Shooter Height:

The next part of the data that I investigated was shooter height and how it affected shot selection and shot accuracy.  We can first look at a basic plot of mean accuracy versus shooter height to see:


At first glance, one might be tempted to conclude that taller players are better shooters, as their overall accuracy tends to be greater on average.  However we can see from juxtaposing the following plots that this is likely due to a bias in shot selection:


Optimal Shot Selection:

The last part of the data that I investigated was shot selection.  Naturally one would expect that the shots most frequently taken are likely to be the most optimal (from an expected value perspective).  Already having plotted accuracy versus shot distance, it's simple to calculate and plot the expected value (of a shot) as a function of shot distance:



Interestingly enough, we can note that the largest EV shots take place at approximately 2.5 feet and 23 feet (3 pointers) from the basket, which are roughly the two distances from which the majority of shots are taken, as seen in the frequency graph on the right.

In the future, I'd like to potentially scrape the NBA Stats website myself to obtain two-dimensional data for shot distance and see how shot selection/accuracy is distributed according to actual location on the court (as opposed to simply distance from the basket).  I'd also like to incorporate shooter/defender height disparity into the analysis of shooting accuracy as well.

About Author

Jack Enyeart

Jack received his Master's in mathematics from Duke University, with a focus in probability theory. He is now an aspiring data scientist, attending NYCDSA's 12 week bootcamp. In his free time, Jack enjoys cooking, watching movies, solving problems...
View all posts by Jack Enyeart >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans 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 boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis 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 seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI