Extended Elo rating system implementation exploiting the equivalence with logistic regression.
Project description
:chess_pawn: EloGrad
Extended Elo rating system implementation exploiting the equivalence with logistic regression.
EloGrad (Elo as Gradient descent) leverages the framing of the
Elo rating system
as logistic regression with stochastic gradient descent
(see Elo as Logistic Regression for a walkthrough)
to offer a collection of extensions to the rating system.
All rating systems are narwhals
compatible for dataframe libraries with
full API support.
:sparkles: Features
- Standard Elo rating system for binary outcomes.
narwhals
compatible.- A
scikit-learn
compatible implementation is available in thesklearn
submodule. - See
examples/nba.ipynb
for an example using NBA data andpolars
.
- Elo rating system for binary outcomes with additional regressors, e.g. home advantage.
- L1 and L2 regularisation supported for additional regressors (see Regularisation).
- See Additional Regressors for the theory and
examples/nba.ipynb
for an example using NBA data andpolars
.
- Elo rating system for count data based on Poisson regression.
narwhals
compatible.- A
scikit-learn
compatible implementation is available in thesklearn
submodule. - See Poisson Elo for the theory and
examples/football.ipynb
for an example using Premier League football data andpandas
.
:book: Installation
You can install elo-grad
with:
pip install elo-grad
For the scikit-learn
compatible rating systems, the sklearn
optional dependencies must be installed as:
pip install elo-grad[sklearn]
:zap: Quick Start
Detailed example notebooks are provided in the examples/
directory.
To install any extra dependencies required to run the notebooks install with:
pip install elo-grad[examples]
:clipboard: Minimal Example
from elo_grad import EloEstimator, Regressor
# Input dataframe with columns
# t | entity_1 | entity_2 | score | home
# sorted (in ascending order) on t
# where t is the Unix timestamp (in seconds) of
# the game and score = 1 if player_1 won and score = 0
# if player_2 won and home is a boolean flag indicating
# if entity_1 has home advantage.
df = ...
estimator = EloEstimator(
k_factor=20,
default_init_rating=1200,
entity_cols=("player_1", "player_2"),
score_col="result",
date_col="t",
init_ratings=dict(home=(None, 0)),
additional_regressors=[Regressor(name='home', k_factor=0.1)],
)
# Get expected scores
expected_scores = estimator.predict_proba(df)
# Get final ratings (of form (Unix timestamp, rating))
ratings = estimator.model.ratings
:compass: Roadmap
In rough order, things we want to add are:
- Head-to-head ratings
- Skellam model support
- Interaction terms
- Other optimizers, e.g. momentum
- Extend plotting support, e.g. plotly
- Support for handling correlation in scores
- Explore any ways we can approximate standard errors for the ratings
:blue_book: References
- Elo rating system: https://en.wikipedia.org/wiki/Elo_rating_system
- Elo rating system as logistic regression with stochastic gradient descent: https://stmorse.github.io/journal/Elo.html
- Elo rating system for NFL predictions: https://fivethirtyeight.com/methodology/how-our-nfl-predictions-work/
- Elo rating system based on Poisson regression: https://github.com/octonion/puzzles/blob/master/elo/poisson.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file elo_grad-0.5.0.tar.gz
.
File metadata
- Download URL: elo_grad-0.5.0.tar.gz
- Upload date:
- Size: 689.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de5f458b19accd84c069370ad3a7fb6693fedf0bf36eec143b6c548ab860c43c |
|
MD5 | bbea32bf86bf11189e64945b61a3c8d7 |
|
BLAKE2b-256 | adb27c189289ce0a5a63630f9cabf926d99421060978ab579d546146e695b4ed |
File details
Details for the file elo_grad-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: elo_grad-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ef5bef13b80e8d50dbb202942123eaef3a55bec0dc79a2d1846309625330de3 |
|
MD5 | 19805ccd2964fb7fa7db72f6b3c92f58 |
|
BLAKE2b-256 | cd880f5b3804d356115617f3686a41e9c848e9037eb25ddd543b02176e4a52c6 |