创建跟踪对手先前对手获胜的列

时间:2019-01-12 10:24:12

标签: python arrays python-3.x pandas numpy

(最后发布的数据集) https://github.com/timoudas/NHL-RatingSystem/blob/master/NHL_Stats 重新创建数据集的代码

如何创建两列来跟踪“对手”对手胜率?

(accumulated wins/accumulated games play) 玩游戏时按顺序进行。

示例:A队参加B队

Team A has previously played Team C and Team D
Team B has previously plaved Team E and Team F

数据集如下所示:

HomeTeam    AwayTeam    HomeWin   AwayWin   TotalGamesPlayedByHomeTeam TotalGamesPlayedByAwayTeam   TotalWinsHomeTeam    TotalWinsAwayTeam
  Team A      Team C       0         1                    0                 0                                0                      0
  Team D      Team A       0         1                    0                 1                                0                      0
  Team B      Team E       1         0                    0                 0                                0                      0
  Team F      Team B       0         1                    0                 1                                0                      1 
  Team A      Team B       1         0                    2                 2                                1                      2  

因此将两列添加到数据集HT_OOR(HomeTeam's Opponents Opponents Record)AT_OOR(AwayTeam's Opponents Opponents Record)。 HT_OOR跟踪AWAY团队的先前对手,AT_OOR跟踪HOME团队的先前对手。

因此,在我的A队与B队之间的游戏示例中,HT_OOR和AT_OOR如下:

HT_OOR= (Team_E_TotalWins + Team_F_TotalWins) / (Team_E_TotalGamesPlayed+Team_F_TotalGamesPlayed)

AT_OOR= (Team_C_TotalWins + Team_D_TotalWins) / (Team_C_TotalGamesPlayed+Team_D_TotalGamesPlayed)

如果使用此方法,则重要的是始终使用最接近的统计信息,因为它们按顺序递增。

其他方法是将Home_Win和Away_Win分组,并将Home_Team和Away分组,然后遍历整个列表,分别计算每个团队的出场和各自的损失。

第5行的结果如下:

HT_OOR    AT_OOR
  0        0.5

由于每一行代表一个由两支球队组成的独特游戏,因此跟踪列(HT_OOR,AT_OOR)必须相对于该行中的HomeTeam和AwayTeam。

如何指定这些条件以使其起作用,这可能吗? 如果有任何疑问,或者我不清楚某件事,请告诉或询问。

Dataset

数据集的屏幕截图,变量:

"a_"=Away Team, "h_"=Home Team, 

HTWins= Total Previous wins HomeTeam

ATWins=Total Previous wins AwayTeam

a_games=Total games played by away team

h_games=Total games played by home team

h_won = Home Team Win

Dataset

    h_WinPerc   a_WinPerc   h_teamID    a_teamID    h_team            a_team                 HTWins ATWins  h_Won   a_Won   a_games h_games game_id
      0.0         0.0         52          10     Winnipeg Jets          Toronto Maple Leafs     0      0       0       1       1       1  2017020001
      0.0         0.0          5          19    Pittsburgh Penguins    St.Louis Blues           0      0       0       1       1       1    2017020002
      0.0         0.0         22          20    Edmonton Oilers Calgary  Flames                 0      0       1       0       1       1    2017020003
      0.0         0.0         28           4    San Jose Sharks         Philadelphia Flyers     0      0       0       1       1       1    2017020004
      0.0         0.0          6          18    Boston Bruins           Nashville Predators     0      0       1       0       1       1    2017020005
      0.0         0.0          7           8    Buffalo Sabres          Montréal Canadiens     0      0       1       0       1       1    2017020006
      0.0         0.0          3          21    New York Rangers        Colorado Avalanche      0      0       0       1       1       1    2017020007
      0.0         0.0          9          15    Ottawa Senators         Washington Capitals     0      0       1       0       1       1    2017020008
      0.0         0.0         17          30    Detroit Red Wings       Minnesota Wild          0      0       1       0       1       1    2017020009
      0.0         0.0         16           5    Chicago Blackhawks      Pittsburgh Penguins     0      0       1       0       1       2    2017020010
      0.0         0.0         24          53    Anaheim Ducks           Arizona Coyotes         0      0       1       0       1       1    2017020011
      0.0         1.0         26           4    Los Angeles Kings       Philadelphia Flyers     0      1       1       0       1       2    2017020012

预期的输出如下。

HT_OOR(HomeTeam's Opponents Opponents Record)(accumulated wins/accumulated games play)

AT_OOR(AwayTeam's Opponents Opponents Record)(accumulated wins/accumulated games play)

0 个答案:

没有答案