How to simulate ELO ratings system for cricket in R/Python

r
python

#1

hello,

I came across the below piece somewhere where they have used Elo rating for predicting IPL winner.

I want to know how such a thing can be implemented in R/Python??
Can someone help me on this??


#2

I never came across Elo ratings before but looked it up. Its a very old method which was traditionally used for rating chess players. I found some links which can guide you better:

Do you wish to apply it on the same problem or a different one? I’ll be glad to discuss further in detail if required.

Cheers!


#3

You could try the PlayerRatings package in R. (https://cran.r-project.org/web/packages/PlayerRatings/PlayerRatings.pdf). It has implementations of Elo & Glicko rating systems.

In fact, you should join the March Machine Learning Madness competition currently running on Kaggle, where you need to predict the outcomes of college basketball matches. Some participants have shared scripts that make use of Elo for this.


#4

This can definitely be implemented in R @hackers

Do you have the data points for the same

Regards,
Anant


#5

I wrote a code snippet for calculating the ELO rakings

# Elo Ratings
# ELO ratings cannot be updated on a transaction basis. The entire win lose data has to be fed and elo rankings will get updated

teams <- data.frame(name=c('team1','team2','team3'),elo=c(0,0,0))
teams$name <- as.character(teams$name)
matches <- data.frame(matchNo <- c(1,2,3),winteam=c('team1','team1','team2'),loseteam=c('team2','team3','team3'))
matches$winteam <- as.character(matches$winteam)
matches$loseteam <- as.character(matches$loseteam)

# Call the function to update the ELo rankings
teams <- updateElo(teams, matches)

# Function to update ELO rakings
updateElo <- function(teams,matches)
{
  teams$updatedElo <- 0
  for(team in teams$name)
  {
    # Denominator
    matchCount <- nrow(matches[matches$winteam==team | matches$loseteam==team,])
    # Numerator
    numerator <- 0
    curteamMatches <- matches[matches$winteam==team | matches$loseteam==team,]
    for(i in 1:nrow(curteamMatches))
    {
      if(curteamMatches[i,2]==team) numerator <- numerator + 400 + teams[teams$name==curteamMatches[i,3],2]
      if(curteamMatches[i,3]==team) numerator <- numerator - 400 + teams[teams$name==curteamMatches[i,2],2]
    }
    teams[teams$name==team,3] <- numerator / matchCount
    
  }
  teams$elo <- teams$updatedElo
  teams$updatedElo <- NULL
  return(teams)
}

**Next Step :slight_smile: **
I am trying to find out if the ELO ranking methodology has a mean. I am trying to experiment with random match results

Regards,
Anant