WinProbability - basketballrelativity/py_ball GitHub Wiki

This section details all the win probability data accessible via the WinProbability class in winprobability.py. The win probability model was developed by Avyay Varadarajan and more detail on the model can be found here.

Parameters

The classes require the corresponding parameters below:

API Param Class Param Definition Valid Values Required
GameID game_id 10-digit string that represents a unique game. The format is two leading zeroes, followed by a season indicator number ('1' for preseason, '2' for regular season, '4' for the post-season), then the trailing digits of the season in which the game took place (e.g. '17' for the 2017-18 season). The following 5 digits increment from '00001' in order as the season progresses. For example, '0021600001' is the game_id of the first game of the 2016-17 NBA regular season. Yes

Example Usage

from py_ball import winprobability

HEADERS = {}  # Request header information

wp = winprobability.WinProbability(game_id="0021900973", headers=HEADERS)

fig = wp.probs(get_values=False) # If get_values = False, a matplotlib.figure.Figure object of the win probability plot is returned
times, probs_home, probs_away, team_abr = wp.probs(get_values=True) # If get_values = True, four objects are returned

# times (list): list of times for which win probability is calculated. The units are seconds remaining in the game
# probs_home (list): list of win probability values for the home team
# probs_away (list): list of win probability values for the away team
# team_abr (list): list of team abbreviations with the home team in the first index and the away team in the second index

See the py_ball README file for information on request headers.