A Python implementation of the ELO rating system for ranking and comparing items (like cars, players, etc.).
- ELO Rating Calculations: Implements the standard ELO formula for rating updates
- Expected Score Calculation: Calculate win probabilities between any two ratings
- Configurable K-Factor: Adjust rating volatility (32 for beginners, 16 for experienced, 8 for masters)
- Interactive Demo: Car comparison example with step-by-step mathematical breakdown
from main import EloRatingSystem
# Initialize with default K-factor of 32
elo = EloRatingSystem(k_factor=32)
# Calculate expected score
expected = elo.expected_score(rating_a=1600, rating_b=1400)
# Update ratings after a match
new_rating_a, new_rating_b = elo.update_ratings(
rating_a=1600,
rating_b=1400,
score_a=1 # 1=win, 0=loss, 0.5=draw
)python main.pyThe demo simulates car comparisons and shows:
- Starting ratings (all equal at 1500)
- Step-by-step rating updates
- Final rankings
- Win probability analysis
- Mathematical breakdown of calculations
The ELO system uses these key formulas:
Expected Score:
E_A = 1 / (1 + 10^((R_B - R_A) / 400))
Rating Update:
R_new = R_old + K × (S - E)
Where:
E= Expected score (0 to 1)S= Actual score (1=win, 0=loss, 0.5=draw)K= K-factor (rating change multiplier)
🏎️ ELO RATING SYSTEM DEMO - Car Rankings
==================================================
Starting ratings (all equal):
Audi R8: 1500
Porsche 911: 1500
VW Golf: 1500
Old Volvo (1990): 1500
FINAL RANKINGS:
==================================================
1. Audi R8: 1632
2. Porsche 911: 1568
3. VW Golf: 1400
4. Old Volvo (1990): 1400
MIT License