Thursday, 17 September 2015

Tableau and the NBA - moving past a static shot chart

For those who know me, I have always wanted to achieve one thing with data - understand the NBA better. If you were (un)lucky enough to hear me talk in Seattle at the Tableau Public session in 2014 you know that the great basketball analysis I had come up with was this:


The Interactive Shot Chart: click on the image to go to Tableau Public


Don’t get me wrong, I was massively proud of creating this. It was the first time that I had used path, background images and a number of other techniques in Tableau. The visualisation allowed me to understand not just whether a shot was made, but added context to the shot by showing additional information about the pass that led to the shot. However, this was not sustainable. It took me four hours to map one quarter of one game. I’m a dedicated fan but there are limits (even when the Spurs are beating the Lakers).


I made an extra step when I stumbled upon the ‘Shot Logs’ on the NBA.com website. Have a look at all of the richness that is available from this part of the site: 


Stats.nba.com - All thanks to SportsVu data

I have already written about how I got the statistics out of this part of the NBA in the following blog: http://www.theinformationlab.co.uk/2015/08/11/the-nba-letting-you-get-closer-to-the-game/ Despite all the goodies in these pages (and the accompanying Rebound logs) this gave me a lot to analyse but still didn’t get me any closer to what I wanted to really create.


This is why I got really excited when a colleague sent me a link to this article in which Savvas shows how to get the X/Y movement data that I have been striving to get my hands on for the last few years. All of this is available from the NBA API. Savvas uses Python and as I’m not the greatest coder in the world, I took the path of ‘least coding’ and set-up Alteryx to do all the hard work for me.


With Alteryx you have the ability to connect to the API and grab the JSON output. By generating numbers you can, create a whole set of URLs from a base to scroll through the various events within a game. As a game returns circa 2 million rows of data through this macro, I haven’t made the macro to return multiple games. With Alteryx’s text input, it allows me to enter a Game ID once and then can reuse in multiple places throughout the macro. I have used this functionality as a second API call is made to bring back the play-by-play information.





You can download the module from here and see what I did at each stage.   


My favourite visualisation that I have created so far with this data allows you to pick any play throughout the game and watch the play unfold. As the ‘Pages’ shelf in server doesn’t allow you to ‘play’ the visualisation, I have uploaded a YouTube video of how this looks on Tableau Desktop.


But you can also get the workbook and ‘play’ it on your Tableau Desktop by downloading from Tableau Public 




No comments:

Post a Comment