Я получил код R для рейтингов Эло команд, участвующих в чемпионате мира. Итак, я попытался сделать то же самое для другой лиги. Я получаю рейтинги очень хорошо, но это должно иметь определенный вес для команд, которые вышли в полуфинал или финал турнира.
Вот код R:
library(dplyr)
matches = readr::read_csv('data.csv')
teams = data.frame(team = unique(c(matches$home_team, matches$away_team)))
teams = teams %>%
mutate(elo = 1500)
matches = matches %>%
mutate(result = if_else(home_score > away_score, 1,
if_else(home_score == away_score, 0.5, 0)))
matches = matches %>%
select(date, home_team, away_team, result) %>%
arrange(date)
library(elo)
for (i in seq_len(nrow(matches)))
{
match = matches[i, ]
# Pre-match ratings
teamA_elo = subset(teams, team == match$home_team)$elo
teamB_elo = subset(teams, team == match$away_team)$elo
# Let's update our ratings
new_elo = elo.calc(wins.A = match$result,
elo.A = teamA_elo,
elo.B = teamB_elo,
k = 30)
# The results come back as a data.frame
# with team A's new rating in row 1 / column 1
# and team B's new rating in row 1 / column 2
teamA_new_elo = new_elo[1, 1]
teamB_new_elo = new_elo[1, 2]
# We then update the ratings for teams A and B
# and leave the other teams as they were
teams = teams %>%
mutate(elo = if_else(team == match$home_team, teamA_new_elo,
if_else(team == match$away_team, teamB_new_elo, elo)))
}
teams %>%
arrange(-elo) %>%
head
print.data.frame(teams)