Skip to main content

:chess_pawn: EloGrad

Extended Elo rating system implementation based on 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 the sklearn submodule.
    • See examples/nba.ipynb for an example using NBA data and polars.
  • Elo rating system for binary outcomes with additional regressors, e.g. home advantage.
  • Elo rating system for count data based on Poisson regression.
    • narwhals compatible.
    • A scikit-learn compatible implementation is available in the sklearn submodule.
    • See Poisson Elo for the theory and examples/football.ipynb for an example using Premier League football data and pandas.

: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
  • Bivariate Poisson model support
  • Interaction terms
  • Other optimizers, e.g. momentum
  • Extend plotting support, e.g. plotly
  • Support hierarchical matches, e.g. tennis matches with sets and games

:blue_book: References

  1. Elo rating system: https://en.wikipedia.org/wiki/Elo_rating_system
  2. Elo rating system as logistic regression with stochastic gradient descent: https://stmorse.github.io/journal/Elo.html
  3. Elo rating system for NFL predictions: https://fivethirtyeight.com/methodology/how-our-nfl-predictions-work/
  4. Elo rating system based on Poisson regression: https://github.com/octonion/puzzles/blob/master/elo/poisson.py

Metadata

Release files for elo-grad 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elo-grad 0.5.1
File Size Uploaded
elo_grad-0.5.1.tar.gz 782.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for elo-grad 0.5.1
File Interpreter ABI Platform
elo_grad-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 796.8 kB

Release files / elo_grad-0.5.1.tar.gz

Download URL elo_grad-0.5.1.tar.gz
Size 782.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c435b7e51b9cbb206fa3de38ff61cd3ef0ad3eb49c8594b0590772048d6f219b
BLAKE2b-256 checksum
How to use checksums
5841bf963824002a4051e39fce67e3cf7bc101c4ce4362400afe1fe2a6b9f718
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.4.20

Release files / elo_grad-0.5.1-py3-none-any.whl

Download URL elo_grad-0.5.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cc88e968b33f1e5fac6d7f687bbd1f9860b52e02bb1031f1879511394ce370c
BLAKE2b-256 checksum
How to use checksums
c71693e8199de1a39b48bcf81154b22c5a4266f37483e12f63568e38ea1a3c24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.4.20

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page