Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Implementing n-player Elo rating in pandas dataframe

$
0
0

Sorry if this is a rather complicated question.I have a pandas dataframe that records the result of races between different players:

Race_ID records different races

Racer_ID records different players

N denotes the number of players in that game

Place denotes the outcome of that game, with 1 being the winner, 2 being the first runner up, etc.

I want to add a new column called Elo_rating to represent the current elo rating of that player using the following algorithm for n-player elo:

  1. If this is the first game for that player, then give them an elo rating of 400:

enter image description here

  1. Compute the expected rating of player x by the following formula:

enter image description here

where D=400.

And if this is the first game for that player, then set E_i = 1/N

  1. After the race result is out, the Score function for player i is given by

S_i = (N - place) / (N(N-1)/2)

So for example, the score for player 1, 2, 3, 4 after the first race (Race_ID = 10055116) are respectively

S_1 = (4-3) / (4(3)/2) = 1/6,

S_2 = (4-2) / (4(3)/2) = 2/6,

S_3 = (4-1) / (4(3)/2) = 3/6,

S_4 = (4-4) / (4(3)/2) = 0/6.

  1. Finally the elo rating update for the next race is given by

E_i <- R_i + 30(S_i - E_i)

So for example the elo rating for the second race (Race_ID = 10055117) is given by

enter image description here

And the desired output is given by

enter image description here

I have no idea how I can approach this problem, but I guess we should start by groupby the Racer_ID and then applying .map but I have no idea how to implement it. Thank you so much.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>