Skip to main content

rankcal

PyPI version Python 3.9+ License: MIT Docs Open In Colab

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 Error
  • ece_at_k(scores, labels, k) - ECE computed only on top-k items
  • reliability_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

Release files for rankcal 0.2.0

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

Source distribution (sdist)

Source distribution for rankcal 0.2.0
File Size Uploaded
rankcal-0.2.0.tar.gz 26.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rankcal 0.2.0
File Interpreter ABI Platform
rankcal-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.1 kB

Release files / rankcal-0.2.0.tar.gz

Download URL rankcal-0.2.0.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
de7766b9461b87cc009deec472e5a97376d3bc4cf800ac24ef99f61a8a3c3508
BLAKE2b-256 checksum
How to use checksums
78de0512246331cb5fa0766249d24f53f38915ea0adf4993771b7de196649f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 5, 2026.

Transparency log

Release files / rankcal-0.2.0-py3-none-any.whl

Download URL rankcal-0.2.0-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a2151dfe5a58a4b4c17431267c5afd31aa5225b515f186f3db60a58bc17bfdc
BLAKE2b-256 checksum
How to use checksums
899b14b8f1261bfcc75f9ebb01c8991623530e5a224f36de6fa7f69383a2feed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

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