Skip to main content

MCGrad: Production-ready multicalibration

Production-ready multicalibration

CI Coverage Documentation Status

PyPI version Python 3.10+ Downloads License: MIT

Open In Colab


What is MCGrad?

MCGrad is a scalable and easy-to-use tool for multicalibration. It ensures your ML model predictions are well-calibrated not just globally (across all data), but also across virtually any segment defined by your features (e.g., by country, content type, or any combination).

Traditional calibration methods, like Isotonic Regression or Platt Scaling, only ensure global calibration—meaning predicted probabilities match observed outcomes on average across all data—but your model can still be systematically overconfident or underconfident for specific groups. MCGrad automatically identifies and corrects these hidden calibration gaps without requiring you to manually specify protected groups.

Global calibration curve showing well-calibrated predictions on average

A globally well-calibrated model: predictions match observed outcomes on average.

Segment-level calibration curves revealing hidden miscalibration in specific groups

The same model showing hidden miscalibration when broken down by segment. MCGrad fixes this.

🌟 Why MCGrad?

  • State-of-the-art multicalibration — Best-in-class calibration quality across a vast number of segments.
  • Easy to use — Familiar interface. Pass features, not segments.
  • Highly scalable — Fast to train, low inference overhead, even on web-scale data.
  • Safe by design — Likelihood-improving updates with validation-based early stopping.

🏭 Production Proven

MCGrad has been deployed at Meta on hundreds of production models. See the research paper for detailed experimental results.

📦 Installation

Requirements: Python 3.10+

Stable release:

pip install mcgrad

Or via conda / mamba:

conda install mcgrad
# or
mamba install mcgrad

Latest development version:

pip install git+https://github.com/facebookincubator/MCGrad.git

🚀 Quick Start

from mcgrad import methods
import numpy as np
import pandas as pd

# Prepare your data in a DataFrame
df = pd.DataFrame({
    'prediction': np.array([0.1, 0.3, 0.7, 0.9, 0.5, 0.2]),  # Your model's predictions
    'label': np.array([0, 0, 1, 1, 1, 0]),  # Ground truth labels
    'country': ['US', 'UK', 'US', 'UK', 'US', 'UK'],  # Categorical feature
    'content_type': ['photo', 'video', 'photo', 'video', 'photo', 'video'],  # Categorical feature
})

# Apply MCGrad
mcgrad = methods.MCGrad()
mcgrad.fit(
    df_train=df,
    prediction_column_name='prediction',
    label_column_name='label',
    categorical_feature_column_names=['country', 'content_type']
)

# Get calibrated predictions
calibrated_predictions = mcgrad.predict(
    df=df,
    prediction_column_name='prediction',
    categorical_feature_column_names=['country', 'content_type']
)
# Returns: numpy array of calibrated probabilities, e.g., [0.12, 0.28, 0.72, ...]

📚 Documentation

💬 Community & Support

📖 Citation

If you use MCGrad in your research, please cite our paper.

DOI

@inproceedings{tax2026mcgrad,
  title={{MCGrad: Multicalibration at Web Scale}},
  author={Tax, Niek and Perini, Lorenzo and Linder, Fridolin and Haimovich, Daniel and Karamshuk, Dima and Okati, Nastaran and Vojnovic, Milan and Apostolopoulos, Pavlos Athanasios},
  booktitle={Proceedings of the 32nd ACM SIGKDD Conference on Knowledge Discovery and Data Mining V.1 (KDD 2026)},
  year={2026},
  doi={10.1145/3770854.3783954}
}

Related Publications

Some of our team's other work on multicalibration:

  • A New Metric to Measure Multicalibration: Guy, I., Haimovich, D., Linder, F., Okati, N., Perini, L., Tax, N., & Tygert, M. (2025). Measuring multi-calibration. arXiv:2506.11251.

  • Theoretical Results on Value of Multicalibration: Baldeschi, R. C., Di Gregorio, S., Fioravanti, S., Fusco, F., Guy, I., Haimovich, D., Leonardi, S., et al. (2025). Multicalibration yields better matchings. arXiv:2511.11413.

Metadata

Release files for MCGrad 0.1.5

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

Source distribution (sdist)

Source distribution for MCGrad 0.1.5
File Size Uploaded
mcgrad-0.1.5.tar.gz 2.5 MB Details

Built distribution (wheel)

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

Total release size: 2.6 MB

Release files / mcgrad-0.1.5.tar.gz

Download URL mcgrad-0.1.5.tar.gz
Size 2.5 MB
Tags Source
SHA-256 checksum
How to use checksums
5366e701654980e48011e64b787223c18b6d50bebe4d30e78851b448e7826520
BLAKE2b-256 checksum
How to use checksums
b67a72bd1a47ba08796559d4c087a54d71d375a77d83a028d4dd8a96b8fdeaaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 3, 2026.

Transparency log

Release files / mcgrad-0.1.5-py3-none-any.whl

Download URL mcgrad-0.1.5-py3-none-any.whl
Size 130.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4de892185994f6f1bcc81c781df32bd2c20ad81e78c0a00e485c0a8bb6b8af45
BLAKE2b-256 checksum
How to use checksums
fbdbd33b1187022f03b36834bcbf4b70f442703a8f0470b766fc29afa44e2769
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.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