Tutorials
Interactive Jupyter notebooks demonstrating how to use MCGrad for multicalibration.
Available Tutorials
What You'll Learn
01. MCGrad Core Algorithm
This comprehensive tutorial covers:
- Why Multicalibration Matters - Understand the limitations of global calibration and why segment-level calibration is important
- MCGrad Basics - Learn how to use the
fit()andpredict()API - Measuring Multicalibration - Use the Multicalibration Error (MCE) metric to evaluate calibration quality
- Visualization - Plot global and segment-level calibration curves
- Advanced Features - Explore feature importance, model serialization, numerical features, and custom hyperparameters
02. Trustworthy LLM Confidence for Downstream Decisions with MCGrad
This tutorial applies the MCGrad workflow to an LLM classifier (Claude Opus 4.6 on Comparative Agendas Project documents) and covers:
- Why Raw LLM Confidence Isn't Trustworthy - Diagnose how an LLM's elicited probabilities over-estimate prevalence per country, by different amounts each time
- Global Calibration Isn't Enough - See why isotonic regression closes the global gap but leaves significant per-segment miscalibration
- Fitting MCGrad on LLM Outputs - Train MCGrad with document metadata as segment features
- Risk-Calibrated Thresholds - Set a confidence threshold once and get the same per-item risk in every country, content type, or cohort
- Per-Segment Prevalence Estimation - Recover unbiased positive rates within any sub-population, ready for stakeholder breakdowns
Running Tutorials
Option 1: Google Colab (Recommended)
Click the "Open in Colab" badge above to run tutorials directly in your browser. No local setup required!
Option 2: Local Jupyter
- Install MCGrad with tutorial dependencies:
pip install "MCGrad[tutorials] @ git+https://github.com/facebookincubator/MCGrad.git"
- Clone the repository and navigate to tutorials:
git clone https://github.com/facebookincubator/MCGrad.git
cd MCGrad/tutorials
jupyter notebook 01_mcgrad_core.ipynb
Option 3: VS Code
Open the .ipynb files directly in VS Code with the built-in Jupyter extension.
Contributing Tutorials
We welcome contributions! If you'd like to add a new tutorial:
- Create a new
.ipynbfile in thetutorials/directory - Follow the naming convention:
XX_descriptive_name.ipynb - Include a Colab setup cell at the top (see existing tutorials for the pattern)
- Add the tutorial to this documentation page
- Submit a pull request
See the Contributing Guide for more details.