資源簡介
python預(yù)測nba比賽結(jié)果
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
Created?on?Sun?Jun??4?16:19:16?2017
@author:?dc
“““
import?pandas?as?pd?
import?math
import?numpy?as?np
from?sklearn?import?linear_model
import?csv
init_elo?=?1600
team_elos?=?{}
#trainteamstat?=?{}
folder?=?‘data‘
def?PruneData(M_stat?O_stat?T_stat):
????#這個(gè)函數(shù)要完成的任務(wù)在于將原始讀入的諸多隊(duì)伍的數(shù)據(jù)經(jīng)過修剪,使其變?yōu)橐粋€(gè)以team為索引
????#排列的特征數(shù)據(jù)
????
????#丟棄與球隊(duì)實(shí)力無關(guān)的統(tǒng)計(jì)量
????pruneM?=?M_stat.drop([‘Rk‘?‘Arena‘]axis?=?1)
????pruneO?=?O_stat.drop([‘Rk‘‘G‘‘MP‘]axis?=?1)
????pruneT?=?T_stat.drop([‘Rk‘‘G‘‘MP‘]axis?=?1)
????
????#將多個(gè)數(shù)據(jù)通過相同的index:team合并為一個(gè)數(shù)據(jù)
????mergeMO?=?pd.merge(pruneM?pruneO?how?=?‘left‘?on?=?‘Team‘)
????newstat?=?pd.merge(mergeMO?pruneT??how?=?‘left‘?on?=?‘Team‘)
????
????#將team作為index的數(shù)據(jù)返回
????return?newstat.set_index(‘Team‘?drop?=?True?append?=?False)
def?GetElo(team):
????#
????try:
????????return?team_elos[team]
????except:
????????team_elos[team]?=?init_elo
????return?team_elos[team]
def?CalcElo(winteam?l
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-06-10?12:20??python-項(xiàng)目一NBA\
?????目錄???????????0??2017-06-10?12:27??python-項(xiàng)目一NBA\data\
?????文件????????4795??2017-03-09?17:50??python-項(xiàng)目一NBA\data\15-16Miscellaneous_Stat.csv
?????文件????????4078??2017-03-09?17:49??python-項(xiàng)目一NBA\data\15-16Opponent_Per_Game_Stat.csv
?????文件????????4057??2017-03-09?17:48??python-項(xiàng)目一NBA\data\15-16Team_Per_Game_Stat.csv
?????文件???????43180??2017-03-10?01:04??python-項(xiàng)目一NBA\data\16-17Schedule.csv
?????文件???????49089??2017-03-09?00:41??python-項(xiàng)目一NBA\data\2015-2016_result.csv
?????文件???????12348??2017-06-05?09:23??python-項(xiàng)目一NBA\data\Train_data.csv
?????文件????????5581??2017-06-10?12:26??python-項(xiàng)目一NBA\p1_NBA_prediction.py
評論
共有 條評論