Skip to main content

Production-ready multicalibration for machine learning

Reason this release was yanked:

Old release, superseded by our actual release

Project description

MCGrad

Production-ready multicalibration for machine learning.

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

🌟 Key Features

  • Powerful Multicalibration - Calibrates across unlimited segments without pre-specification
  • Data Efficient - Borrows information like modern ML models
  • Lightweight & Fast - Orders of magnitude faster than NN-based calibration
  • Improved Performance - Likelihood-improving with significant PRAUC gains

📚 Documentation

Full documentation is available at: https://facebookincubator.github.io/MCGrad/

Two Documentation Systems

This project uses a dual documentation approach:

  1. User Guide (Docusaurus) - Available at https://facebookincubator.github.io/MCGrad/

    • Getting started guides, tutorials, and conceptual documentation
    • Built from the website/ directory
  2. API Reference (Sphinx) - Available at https://multicalibration.readthedocs.io/

    • Auto-generated from Python docstrings
    • Detailed API documentation for all classes and functions
    • Built from the sphinx/ directory

🚀 Quick Start

from multicalibration 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 features
    'content_type': ['photo', 'video', 'photo', 'video', 'photo', 'video'],  # defining segments
})

# 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']
)

📦 Installation

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

For development:

git clone https://github.com/facebookincubator/MCGrad.git
cd MCGrad
pip install -e ".[dev]"

🔧 Development

Pre-commit Hooks

This project uses pre-commit hooks for code quality:

pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-push

What runs:

  • On commit: flake8 checks your code
  • On push: pytest runs the test suite

Building Documentation

cd website
npm install
npm start

Open http://localhost:3000 to view the docs locally.

📄 License

MIT License - see LICENSE for details.

🤝 Contributing

We welcome contributions! See Contributing Guide for details.

📖 Citation

If you use MCGrad in your research, please cite:

@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}
}

Paper: MCGrad: Multicalibration at Web Scale (KDD 2026)

Related Publications

For more on multicalibration theory and applications:

  • Measuring Multi-Calibration: Guy, I., Haimovich, D., Linder, F., Okati, N., Perini, L., Tax, N., & Tygert, M. (2025). Measuring multi-calibration. arXiv:2506.11251.

  • Multicalibration Applications: 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.

📊 CI Status

CI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcgrad-0.1.0.tar.gz (93.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcgrad-0.1.0-py3-none-any.whl (58.1 kB view details)

Uploaded Python 3

File details

Details for the file mcgrad-0.1.0.tar.gz.

File metadata

  • Download URL: mcgrad-0.1.0.tar.gz
  • Upload date:
  • Size: 93.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12+meta

File hashes

Hashes for mcgrad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 adbae470ab8f443dc9168d9fdc380da79a8434622d9fcb93382944030106202b
MD5 dfb6edf8a2c1f5d57561fc21c4fef6f5
BLAKE2b-256 c109a45b404b9fdd2e60f9cd1379627c9c0631d2d69e5fc3b97c403e0d13b6b3

See more details on using hashes here.

File details

Details for the file mcgrad-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcgrad-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 58.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12+meta

File hashes

Hashes for mcgrad-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0d257e5acbb275226e8fbc30ee2b027aa1d23f74cad441f862506b6015bbfec
MD5 05b020638058dd56b9b5ff37ce1b46e8
BLAKE2b-256 d4c73f69e9b320add911c3337d1bbc6c94f8fa37f1eb706400b5821eea4ca26a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page