Calibration and uncertainty quantification for ranking systems
Project description
rankcal
Calibration and uncertainty quantification for ranking systems. PyTorch-first.
Why rankcal?
Existing calibration libraries treat calibration as a classification problem. But ranking decisions happen at the top-k, and miscalibration there is what actually breaks business outcomes.
rankcal provides:
- Ranking-aware calibration metrics - ECE@k, top-k reliability diagrams
- Monotonic calibrators - Temperature scaling, isotonic regression, splines, neural networks
- Decision analysis - Risk-coverage curves, utility optimization
Installation
pip install rankcal
For development:
pip install -e ".[dev]"
Quick Start
import torch
from rankcal import TemperatureScaling, ece_at_k, reliability_diagram
# Your ranking scores and binary relevance labels
scores = torch.tensor([0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1])
relevance = torch.tensor([1, 1, 0, 1, 0, 0, 1, 0, 0])
# Fit a calibrator
calibrator = TemperatureScaling()
calibrator.fit(scores, relevance)
# Calibrate scores
calibrated = calibrator(scores)
# Evaluate calibration at top-k
ece = ece_at_k(calibrated, relevance, k=5)
print(f"ECE@5: {ece:.4f}")
# Visualize calibration
fig = reliability_diagram(calibrated, relevance, k=5)
fig.savefig("reliability.png")
Calibrators
| Calibrator | Differentiable | Parametric | Description |
|---|---|---|---|
TemperatureScaling |
✓ | ✓ | Single learned temperature parameter |
IsotonicCalibrator |
✗ | ✗ | Non-parametric, piecewise constant |
PiecewiseLinearCalibrator |
✓ | ✓ | Monotonic piecewise linear interpolation |
MonotonicNNCalibrator |
✓ | ✓ | Neural network with monotonicity constraints |
GPU Support
All calibrators are PyTorch nn.Module subclasses and support GPU acceleration:
import torch
from rankcal import TemperatureScaling
# Move calibrator to GPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
calibrator = TemperatureScaling().to(device)
# Fit with data on GPU
scores = scores.to(device)
labels = labels.to(device)
calibrator.fit(scores, labels)
# Inference on GPU
test_scores = test_scores.to(device)
calibrated = calibrator(test_scores)
Run GPU tests with:
pytest tests/test_gpu.py --device cuda # or --device mps on Mac
Metrics
ece(scores, labels)- Expected Calibration Errorece_at_k(scores, labels, k)- ECE computed only on top-k itemsreliability_diagram(scores, labels, k=None)- Visualization of calibration
Citation
If you use rankcal in academic work, please cite:
@software{hodge2026rankcal,
author = {Hodge, John},
title = {rankcal: Calibration for Ranking Systems},
year = {2026},
url = {https://github.com/jman4162/rankcal},
version = {0.2.0}
}
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rankcal-0.2.0.tar.gz.
File metadata
- Download URL: rankcal-0.2.0.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de7766b9461b87cc009deec472e5a97376d3bc4cf800ac24ef99f61a8a3c3508
|
|
| MD5 |
af87db4a44221a8e1a376044c2779fea
|
|
| BLAKE2b-256 |
78de0512246331cb5fa0766249d24f53f38915ea0adf4993771b7de196649f92
|
Provenance
The following attestation bundles were made for rankcal-0.2.0.tar.gz:
Publisher:
publish.yml on jman4162/rankcal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rankcal-0.2.0.tar.gz -
Subject digest:
de7766b9461b87cc009deec472e5a97376d3bc4cf800ac24ef99f61a8a3c3508 - Sigstore transparency entry: 919777710
- Sigstore integration time:
-
Permalink:
jman4162/rankcal@c5e49d8cdb175bee2347fc6722f79080f88e3fc6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jman4162
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c5e49d8cdb175bee2347fc6722f79080f88e3fc6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rankcal-0.2.0-py3-none-any.whl.
File metadata
- Download URL: rankcal-0.2.0-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a2151dfe5a58a4b4c17431267c5afd31aa5225b515f186f3db60a58bc17bfdc
|
|
| MD5 |
c741d686162edec1d134bcacf2aed212
|
|
| BLAKE2b-256 |
899b14b8f1261bfcc75f9ebb01c8991623530e5a224f36de6fa7f69383a2feed
|
Provenance
The following attestation bundles were made for rankcal-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on jman4162/rankcal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rankcal-0.2.0-py3-none-any.whl -
Subject digest:
3a2151dfe5a58a4b4c17431267c5afd31aa5225b515f186f3db60a58bc17bfdc - Sigstore transparency entry: 919777713
- Sigstore integration time:
-
Permalink:
jman4162/rankcal@c5e49d8cdb175bee2347fc6722f79080f88e3fc6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jman4162
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c5e49d8cdb175bee2347fc6722f79080f88e3fc6 -
Trigger Event:
release
-
Statement type: