Margin-dependent Elo ratings and predictions model
.. image:: https://travis-ci.org/morelandjs/melo.svg?branch=master :target: https://travis-ci.org/morelandjs/melo
moreland.dev/projects/melo <https://moreland.dev/projects/melo>
_
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
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:]])
spreads = [int(h) - int(a) for h, a in zip(scores_home, scores_away)]
k = 0.245 lines = np.arange(-50.5, 51.5) regress = lambda months: .413 if months > 3 else 0 regress_unit = 'month' commutes = False
nfl_spreads = Melo(k, lines=lines, commutes=commutes, regress=regress, regress_unit=regress_unit)
nfl_spreads.fit(dates, teams_home, teams_away, spreads)
time = nfl_spreads.last_update
mean = nfl_spreads.mean(time, 'CLE', 'KC') print('CLE VS KC: {}'.format(mean))
rankings = nfl_spreads.rank(time, statistic='mean') for team, rank in rankings: print('{}: {}'.format(team, rank))
.. _numpy: http://www.numpy.org .. _pip: https://pip.pypa.io .. _scipy: https://www.scipy.org