All Projects → christopherjenness → Nba Player Movement

christopherjenness / Nba Player Movement

Visualization and analysis of NBA player tracking data

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Nba Player Movement

nba-smart-contracts
Smart contracts and transactions for Topshot, the official NBA digital collectibles game on the Flow Blockchain
Stars: ✭ 316 (+102.56%)
Mutual labels:  nba
Nba
Node.js client for nba.com API endpoints
Stars: ✭ 637 (+308.33%)
Mutual labels:  nba
Nbareact
🏀 iOS and Android NBA app created with React Native
Stars: ✭ 101 (-35.26%)
Mutual labels:  nba
mysportsfeeds-node
NodeJS wrapper for the MySportsFeeds Sports Data API
Stars: ✭ 62 (-60.26%)
Mutual labels:  nba
Nba Player Movements
🏀 Visualization of NBA games from raw SportVU data logs
Stars: ✭ 481 (+208.33%)
Mutual labels:  nba
Nba api
An API Client package to access the APIs for NBA.com
Stars: ✭ 881 (+464.74%)
Mutual labels:  nba
nba-stats-client
🏀 JavaScript Client for stats from NBA.com
Stars: ✭ 29 (-81.41%)
Mutual labels:  nba
Flutter app
🔥🔥🔥本项目包括各种基本控件使用(Text、TextField、Icon、Image、Listview、Gridview、Picker、Stepper、Dialog、Slider、Row、Appbar、Sizebox、BottomSheet、Chip、Dismissible、FlutterLogo、Check、Switch、TabBar、BottomNavigationBar、Sliver等)、豆瓣电影、tubitv、每日一文、和天气、百姓生活、随机诗词、联系人、句子迷、好奇心日报、有道精品课、高德定位、音乐播放器🎵、追书神器等板块
Stars: ✭ 2,140 (+1271.79%)
Mutual labels:  nba
Sprintnba
🏀 NBA客户端
Stars: ✭ 629 (+303.21%)
Mutual labels:  nba
Basketball analytics
Repository which contains various scripts and work with various basketball statistics
Stars: ✭ 88 (-43.59%)
Mutual labels:  nba
Basketball reference web scraper
NBA Stats API via Basketball Reference
Stars: ✭ 279 (+78.85%)
Mutual labels:  nba
Nba Go
🏀 💻 The finest NBA CLI.
Stars: ✭ 3,634 (+2229.49%)
Mutual labels:  nba
Xbmc.plugin.video.nba
Kodi plugin to watch NBA games with nba league pass
Stars: ✭ 42 (-73.08%)
Mutual labels:  nba
NBA-analytics
Short, offhand analyses of the NBA
Stars: ✭ 37 (-76.28%)
Mutual labels:  nba
Nba Prediction
Predict scores of NBA games using regularized matrix completion
Stars: ✭ 128 (-17.95%)
Mutual labels:  nba
nba-analysis
Using machine learning libraries to analyze NBA data
Stars: ✭ 14 (-91.03%)
Mutual labels:  nba
Nbaplus
A concise APP about NBA News and Event with RxJava and EventBus
Stars: ✭ 701 (+349.36%)
Mutual labels:  nba
Nba Movement Data
SportVU movement tracking data.
Stars: ✭ 154 (-1.28%)
Mutual labels:  nba
Deepplaybyplay
Labelling NBA action using deep learning 🏀
Stars: ✭ 143 (-8.33%)
Mutual labels:  nba
All Nba
Android app for NBA fans. Features live scores, highlights and Reddit integration for discussions.
Stars: ✭ 65 (-58.33%)
Mutual labels:  nba

NBA player tracking visualization and analysis

This library contains useful methods for visualizing and analyzing NBA player tracking data.

The data is located here and contains all player and ball locations for NBA games from the 2015-16 season. Play-by-play data is obtained from nba.stats.com.

Example visualizations are shown below.

System Requirements

  • curl
  • ffmpeg
  • p7zip

TODO

  • Long term solution for play-by-play data. This may break at any moment. See here
  • Python 3 support. See here

Visualization

Note, these examples use watch_play() to visualize plays. This method is extremely slow. animate_play() is much faster since it streams frames directly to ffmpeg without writing them to disk first.

To visualize games from the tracking data, the Game class in game.py is used.

from game import Game
game = Game('01.08.2016', 'POR', 'GSW')
game.watch_play(game_time=6, length=120, commentary=False)

NoCommentary

To easily follow the flow of the game, commentary can be added.

game.watch_play(game_time=6, length=120, commentary=True)

Commentary

If you are interested in a single player, they can easily be tracked.

game.watch_play(game_time=2007, length=10, highlight_player='Stephen Curry', commentary=False)

Curry3

All of a players actions can be extracted and viewed with a single method call. Currently, actions can be in ['all_FG', 'made_FG', 'miss_FG', 'rebound'], but this method can be easily extended to include any action.

game.watch_player_actions("Stephen Curry", "made_FG")
"""
This method will output a video for each of Steph's made FGs in the game, 
however, I am just diplaying one of them.
"""

CurryFG

Analysis (In Progress)

Here, we analyze two aspects of basketball that are difficult to address without player tracking data:

  • Defensive Spacing
  • Player/Team Velocity

Defensive Spacing

NBA commentators often praise offensive teams who can "Space the defense". Essentially, if an offensive team can draw out defenders to the three point line, passing lanes will open up and drives to the basket will be less clogged and more efficient. Here we analyze how effectively teams can space the defense.

The workhorse of this analysis is scipy.spatial.ConvexHull which measures the convex hull of the defense (larger convex hull = more spaced defense). This can be visualized:

game.watch_play(121, 10, commentary=False, show_spacing='home')

SpacingPlay

spacing_analysis.py contains the code for the following analysis. To process the data, only "set plays" were analyzed. Since "transition plays" have unique spacing properties, we limited this analysis to "standard" plays where the offense and defense are set.

Which teams are best at spacing the defense? (Remember, spacing the defense more is thought to be better). If we average over all time points for each team, we get the following:

SpacingBar

Interestingly, we see that Detroit is the best team at spacing defenses. This is something that has been anecdotally documented by Mike Prada, and the data back up his claims. Additionally, teams like Cleveland that are thought to have a modern offense, are great at spacing the defense.

But the question is: Does spacing the defense help you win? Here we look at the score differential vs defensive spacing and we see a positive correlation. In fact, spacing the defense an extra 5 square feet correlates with increasing the score differential 4.25 points!

SpacingScore

If you stare at this graph long enough, you can notice it also shows the level of home court advantage in the NBA. If you are interested, you can read an analysis of home court advantage I did here.

How can a team space the defense better? Intuitively, spacing your offense will draw out the defense. The plot below looks at each game, and plots how spaced the offenses and defenses were. Clearly, a more spaced offense correlates with a more spaced defense.

SpacingOffDeff

But when you break it down by team, how effectively can each team space the defense? Below is a plot of each teams average offensive spacing plotted against how well they can space the opponent's defense. As expected, if a team has a well spaced offense, their opponents defense is more spaced. There are a few interested exceptions though.

TeamSpacing

Notice Toronto (TOR). Toronto has a hard time spacing the defense even though they space out their offense. This is likely due to their star DeMar DeRozan being a shooting liability. Defenders don't need to guard him out on the 3PT line, so they can keep the paint clogged.

Notice San Antonio (SAS). San Antonio can effectively space the defense without spacing out their offense. This may be due to having one of the best 3PT shooters in the league, Kawhi Leonard, who needs be guarded religiously at the 3PT line.

Currently, I'm working on breaking down defensive spacing per play to see the effect on individual plays instead of aggregated game data. This is yielding interesting insights.

Player Velocity

Player tracking data provides insight into tean's and player's velocity. Here we analyze how player speed affects the flow of the game. The analysis code can be found in velocity_analysis.py.

Using the visualization shwon above, team velocities can be shown as the game progresses:

game = Game('01.08.2016', 'POR', 'GSW')
watch_play_velocities(game, game_time=7, length=54)

TeamVelocity

Alternatively, individual player velocities can be visualized:

game = Game('01.08.2016', 'POR', 'GSW')
watch_play_velocities(game, game_time=7, length=54, highlight_player='Stephen Curry')

StephVelocity

Different teams have different offense/defensive scheme's that require different amounts of running. When we break down velocity by team, we can look at how much effort each team's scheme takes. (Note: I threw out all transition data, since I was interested in 'set' plays).

OffenseVelocity

What we see makes sense- The Spurs have the most running incorporated into their offense. The Spurs are known for their "flowing" offense, so this makes sense.

DefenseVelocity

Looking at defense is a bit more complicated. Defensive velocity takes into account a number of things: closing out, switching, zoning, etc. We will need to break these down to get real insight.

One aspect of basketball that is currently hard to evaluate is player fatigue. Tracking player velocity, we can see how it decreases over the course of a game as a metric for fatigue.

What we see is some teams, such as the Indiana Pacers decrease in offensive velocity as the game progresses (each dot is the average velocity of a single game).

INDfatigue

Interestingly, while the Spurs have the highest offensive velocity in the league, they show no fatigue over the course of a game. This reflects the speculated culture of the Spurs.

SASfatigue

This will be more insightful when we break down fatigue by player, since different players are affected differentially.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].