aaronengland/game_predictions

A package to predict points scored for the home team and away team as well as home team win probability based on previous performance.
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
game_predictions.egg-info
game_predictions
.gitignore
requirements.txt
setup.py

game_predictions

A package to predict points scored for the home team and away team as well as home team win probability based on previous performance.

To install, use: pip install git+https://github.com/aaronengland/game_predictions.git

Key assumptions:

• home_team must have played at least 1 home game prior to prediction.
• away_team must have played at least 1 away game prior to prediction.
• Argument arrays must be the same length.

How does it work?

The algorithm uses points scored by the home team when they are the home team [1], points allowed by the away team when they are the away team [2], points scored by the away team when they are the away team [3], and points allowed by the home team when they are the home team [4] to generate predictions for home points scored and away points scored.

[1]

[2]

[3]

[4]

To predict points scored by the home team, a random draw is taken from a Poisson distribution [a] with a lambda of the mean (weighted or unweighted) points scored by the home team when they have been the home team [5]. This value is averaged with a random draw from a Poisson distribution with a lambda of the mean points allowed by the away team when they are the away team [6] [7].

[a]

[5]

[6]

[7]

The same logic is used to predict points scored by the away team. To predict points scored by the away team, a random draw is taken from a Poisson distribution with a lambda of the mean points scored by the away team when they are the away team [8]. This value is averaged with a random draw from a Poisson distribution with a lambda of the mean points allowed by the home team when they are the home team [9] [10].

[8]

[9]

[10]

This sequence of draws and calculations is repeated for n_simulations. Probability of the home team winning is calculated by the sum of instances where the the predicted points scored by the home team is greater than the predicted points scored by the away team divided by n_simulations[11].

[11]

Final predicted points scored by the home and away teams are calculated by taking the mean of the predicted points scored by the home team and away teams, respectively [12] [13].

[12]

[13]

Arguments:

• home_team_array: array of the home team for each contest
• home_score_array: array of the points scored by the home team for each contest
• away_team_array: array of the away team for each contest
• away_score_array: array of the points scored by the away team for each contest
• home_team: string of the home team for the contest in which to predict
• away_team: string of the home team for the contest in which to predict
• n_simulations: number of draws from the Poisson distribution for each game (default = 1000)
• weighted_mean: a boolean for the user to determine mean points scored/allowed as a weighted average (i.e., more recent games carry more weight; True) or a [regular] average (False; default = True)

Example:

# import dependencies
from game_predictions import game_predictions
import pandas as pd

# import data

# complete simulation(s)
game_simulation = game_predictions(home_team_array=df['home_team'],
home_score_array=df['home_score'],
away_team_array=df['away_team'],
away_score_array=df['away_score'],
home_team='Name of Home Team',
away_team='Name of Away Team',
n_simulations=1000,
weighted_mean=True)

# get distribution of home points
home_points_distribution = game_simulation.home_score_prediction_list

# get distribution of away points
away_points_distribution = game_simulation.away_score_prediction_list

# get the predicted home score
predicted_home_score = game_simulation.mean_home_score

# get the predicted away score
predicted_away_score = game_simulation.mean_away_score

# get the predicted win probability
predicted_win_probability = game_simulation.prop_home_win

You can’t perform that action at this time.