与利润相关的ELO评级和预测。
melo的Python项目详细描述
利润相关的ELO评级和预测模型
快速启动
要求:python 2.7或3.3+与numpy和scipy。
使用pip:
安装最新版本pip install melo
示例用法:
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 bias = 0.166 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 nfl_spreads.fit(dates, teams_home, teams_away, spreads, bias=bias) # specify a comparison time time = nfl_spreads.last_update # predict the mean outcome at that time mean = nfl_spreads.mean(time, 'CLE', 'KC', bias=bias) 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))