On the trade history and dynamics of NBA teams

While good draft picks and deft management can help you win championships, there is no doubt that NBA teams can massively gain, or lose, by trading players with one another. Here, I played around with some publicly available data given at basketball-reference.com, and had a look at the numbers behind all trades undertaken in the NBA from 1948 to present.

After some quick Python scraping and data cleaning, I first looked at the overall number of trades that were performed in the NBA during the period 1948-present.

NBA_trades_per_year

Total number of trades completed by all NBA teams active between the 1948 and 2014 seasons.

Clearly, we see that the number of trades grows as we move along the years, which can probably be attributed to many factors such as the increasing ease of travelling/mobility and the growing number of teams in the NBA (Of course, the 2014 season is still ongoing so all the number are not all in yet!). Next, I set out to look at whether any NBA teams showed preferential attachment with one another, i.e. do any NBA teams show apreference towards trading with one another rather than with other teams? This could easily be summarized by constructing an adjacency matrix M of dimension N x N (where N is the number of NBA teams), in which each cell N(i, j) gives the number of trades operated between team i and j. For simplicity, I restricted the analysis to teams that are currently active.

Historical_trades_NBA

While the plot above is pretty(ish), it is not very informative. The data is a lot more instructive if visualized as a mixed correlation plot (use the corrplot package!… we’ll also conveniently ignore the obvious caveat that I have not normalized the data for how long each team has been in the NBA….)

NBA_trade_partners_corrplot

Adjacency matrix of number of trades completed between all pairs of currently active NBA teams. This includes all historical trade data from 1948 to present.

We can take this a step further and ask ourselves which teams have had the most success with trades, and also what are the best indivual trades ever performed in the history of the NBA? For this, I collected the win share data associated to each trade. The win share (WS) metric is an estimate of the number of wins produced by a player, and is a good way to determine how many victories an NBA player contributed to his team during his tenure there (more details can be found here). By computing the differential win share per trade (WS gained in trade – WS lost in trade), it is possible to gain an insight in the quality of each trade.

win_shares_per_trade

Distribution of win shares gained or lost by each team in the NBA. This includes all historical trade data from 1948 to present.

In the plot above, I marked inactive teams with a hyphen. We can see that the three currently active teams with the highest mean win share per trade are the LA Lakers, Dallas Mavericks and LA Clippers. In terms of win shares, the three greatest trade ever completed were:

  • June 9, 1980: the Boston Celtics traded a 1980 1st round draft pick (used to select Rickey Brown) and a 1980 1st round draft pick (used to select Joe Barry Carroll) to the Golden State Warriors for Robert Parish and a 1980 1st round draft pick (used to select Kevin McHale).
  • June 24, 1998: the Dallas Mavericks traded Robert ‘Tractor’ Traylor to the Milwaukee Bucks for Pat Garrity and Dirk Nowitzki (!)
  • July 11, 1996: the Charlotte Hornets traded Kobe Bryant to the Los Angeles Lakers for Vlade Divac.

Ultimately, I would like to create an interactive version of the plot above, so that details of each trade appear when the mouse is hovered over any given point. This is currently a work in progress that I will eventually publish here. All the relevant code for this analysis can be found on my github account.

And the most loyal fans in the NBA are…

NBA basketball is the one the sports I enjoy watching the most. As I was ordering my (undisclosed amount)th beer while watching a game during after-work hours, it occurred to me how often I had seen sparsely populated arenas during games, with large areas of seats going unoccupied. This got me to thinking about the average fan attendance for NBA teams, what could be the factors influencing attendance, and ultimately, which NBA team had the most loyal fans?

After some online browsing, Python scraping and data cleansing, I was able to obtain a good amount of data from the awesome guys at basketball-reference.com. Unfortunately, I could not find any records of fan attendance beyond 1981, so this analysis will be restricted to the period between 1981 to 2013 (with records for 2002-2006 also missing). First, I wanted to see if there were any trends in NBA fan attendance per season.

fig_League_attendance_by_year

Fan attendance for each NBA teams during the seasons 1981 to 2013. Years marked with a red asterik represent shortened seasons due to a lockout. Data for the year 2002 to 2006 was not available

The two most striking features of the plot above are the obvious increase in fan attendance from 1981 to 1995, and the subsequent stagnation thereafter. This makes sense, since this period is widely regarded as the golden era and renaissance of basketball, full of rivalries and Hall of Fame players in their prime. Unsurprisingly, the year 1999 and 2012, which were both shortened by ~4 months due to a lockout, saw a drop in total number of fan attendance (purely as a result of lesser games being played – if I were more rigorous, I would normalize for this and also the overall US population, but I wanted to visualize the raw numbers).

Next, I investigated whether team success (the net number of wins per season) during a season could be an indicator of fan attendance. Not surprisingly, teams that won more also attracted more fans (doh!). This was true regardless of the conference in which the team was (East or West).

fig_attendance_team_success

Fan attendance as a function of number of wins for all NBA teams during the period of 1981-2013

I also looked at whether fans were more attracted by teams that scored a lot, or by teams that put an emphasis on defense. However, I had to consider historical trends in scoring, and adjust for the fact that defenses/offenses have gotten more sophisticated over time. Therefore, I decided to look at the fan attendance numbers of each NBA team during a given season, and plot that as a function team’s deviation from the median number of points scored by all teams during that season. The plot below shows the aggregate of all points after considering each individual season between 1981 and 2013. Interestingly, although teams that score more attract more fans, it seems that good defense is even more likely to attract crowds.

fig_correlation_points_attendance

Fan attendance as a function of the number of points scored for and against the home team. To adjust for the variability in offensive/defensive points scored at each season, the attendance numbers are plotted against the home team’s deviation from the season average.

Of course, the caveat of the above plot is that teams that score a lot and/or defend well are more likely to win, and thus attract more fans. Indeed, winning teams usually develop bandwagon fans and thus inflate their attendance numbers. Therefore, I sought to find out who were the most loyal fans in the NBA. In my mind, the mark of a truly loyal fanbase is one that shows up to support its team regardless of win/loss ratio. For these reasons, I plotted the fan attendance of each NBA team normalized per number of wins.

fig_attendance_per_win

And so the most loyal fanbase are the good people of Memphis, Minnesota and Toronto!

I will add all the relevant code to my github account soon (basically as soon as I’ve commented it!)

On the rise of Big Data and Data Science

This post is going to differ slightly from the data-orientated material that I usually publish. I was recently playing around with the Google trends API and came across some very interesting…well….trends. There has definitely been a huge amount of publicity surrounding “Big Data”, maybe even too much. For those of us who have been working in academia, large datasets were becoming a natural day-to-day occurrence that, in my opinion, was a byproduct of the ever-increasing computational power at our disposal. While, there is no doubt that we have arrived in an era in which diverse data can be continuously collected in large volumes, this will only be of any use if statistically and computationally-savvy individuals are put the task of analyzing and retrieving the most relevant elements of the data. Here, I will show just how Big Data and Data Science has been on everyone’s mind for the last few years.

A search for Big Data reveals the sharp growth in searches from 2011 onwards:

Screen Shot 2014-04-05 at 11.39.23 PM

Google trend data for searches of the phrase “Big Data”.

We can also see the origin of these searches across the globe on the scale of countries and cities, with a particularly strong cluster located in India but also South Korea.

Screen Shot 2014-04-06 at 10.41.53 AM

Geotagging of countries where Google searches involving the phrase “Big Data” were made.

 

Screen Shot 2014-04-05 at 11.49.34 PM

Geotagging of cities where Google searches involving the phrase “Big Data” were made.

Alongside the rise of Big Data was the acknowledgement that data scientists would be required to analyze this data, which was reflected by the sharp increase of searches for “data scientist” and also “data scientist jobs”

Screen Shot 2014-04-06 at 12.01.51 AM

Google trend data for searches of the phrase “Data Scientist”.

Screen Shot 2014-04-05 at 11.55.33 PM

Google trend data for searches of the phrase “Data Science Jobs”.

Clearly, the interest is there and doesn’t appear to slow down for now. On that note, I would love to start a project in which you could predict whether a trend is there to stay based off historical trend data for google – that would be a neat little side-project!