Fit Bradley–Terry Ratings from Pairwise Votes

medium
Unit 14 · Evaluation II0/3 to milestone

Chatbot Arena ranks models from millions of "A vs B" votes. Online Elo depends on the order of the votes. The Bradley–Terry model instead fits all the votes at once: each model has a strength pi>0p_i > 0, and P(i beats j)=pipi+pjP(i \text{ beats } j) = \frac{p_i}{p_i + p_j}.

Fit it with Hunter's MM algorithm: repeat

pi←Wi∑j≠inijpi+pjp_i \leftarrow \frac{W_i}{\sum_{j \ne i} \frac{n_{ij}}{p_i + p_j}}

where WiW_i is i's total wins and nijn_{ij} the number of games between i and j, then rescale so the geometric mean of p is 1. Stop when the largest change in p is below tol.

Implement:

  • fit_bt(battles, iters=1000, tol=1e-10): battles is a list of (winner, loser) name pairs. Return {name: p}. (Assume every model has at least one win and one loss.)
  • to_elo(strengths, base=1000): base + 400 * log10(p)
  • win_prob(strengths, a, b)
#evaluation#rankings#statistics2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Fit Bradley–Terry Ratings from Pairwise Votes · TechGradify