Skip to main content

Margin dependent Elo ratings and predictions.

Project description

Margin-dependent Elo ratings and predictions model

Quick start

Requirements: Python 2.7 or 3.3+ with numpy and scipy.

Install the latest release with pip:

pip install melo

Example usage:

import pkgutil
import numpy as np
from melo import Melo

# the package comes pre-bundled with an example dataset
pkgdata = pkgutil.get_data('melo', 'nfl.dat').splitlines()
dates, teams_home, scores_home, teams_away, scores_away = zip(
    *[l.split() for l in pkgdata[1:]])

# define a binary comparison statistic
spreads = [int(h) - int(a) for h, a
    in zip(scores_home, scores_away)]

# hyperparameters and options
k = 0.245
lines = np.arange(-50.5, 51.5)
regress = lambda months: .413 if months > 3 else 0
regress_unit = 'month'
commutes = False

# initialize the estimator
nfl_spreads = Melo(k, lines=lines, commutes=commutes,
                   regress=regress, regress_unit=regress_unit)

# fit the estimator to the training data, teams_home, teams_away, spreads)

# specify a comparison time
time = nfl_spreads.last_update

# predict the mean outcome at that time
mean = nfl_spreads.mean(time, 'CLE', 'KC')
print('CLE VS KC: {}'.format(mean))

# rank nfl teams at end of 2018 regular season
rankings = nfl_spreads.rank(time, statistic='mean')
for team, rank in rankings:
    print('{}: {}'.format(team, rank))

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for melo, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size melo-1.1.0-py3-none-any.whl (25.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size melo-1.1.0.tar.gz (26.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page