Recalibrating AI Probabilities: Platt and Isotonic Methods
Many artificial intelligence models generate output scores that do not accurately reflect true probabilities, meaning a prediction confidence of eighty percent does not always correlate to an eighty percent chance of being correct. This article explores how machine learning practitioners resolve this discrepancy through probability calibration. Specifically, it examines two foundational post-processing techniques—Platt scaling and isotonic regression—detailing the mathematical mechanisms they use to align a trained model's raw outputs with real-world likelihoods, and comparing when to use each approach.
The Need for Probability Calibration
When a classification model is trained, its primary objective is usually to separate different classes as accurately as possible, rather than to estimate precise probabilities. Algorithms like Support Vector Machines (SVMs), boosted decision trees, and deep neural networks often produce distorted probability distributions. For instance, boosted trees tend to push predicted probabilities away from zero and one, while deep neural networks frequently become overconfident, clustering predictions near the extremes. Recalibration fixes this by taking the raw output scores of a trained model and mapping them to calibrated probabilities using a separate validation dataset.
How Platt Scaling Works
Platt scaling is a parametric approach to probability calibration, originally developed to turn the uncalibrated distance outputs of Support Vector Machines into genuine probabilities. It works by fitting a logistic regression model directly onto the raw output scores of the primary classifier.
The mechanism follows a specific mathematical transformation:
- Extract Raw Scores: The trained AI model processes a validation dataset and outputs uncalibrated scores (often called logits), denoted as \(f(x)\).
- Apply the Sigmoid Function: Platt scaling passes these raw scores through a parameterized sigmoid function: \(P(y=1|x) = \frac{1}{1 + \exp(A \cdot f(x) + B)}\).
- Optimize Parameters: The parameters \(A\) and \(B\) are learned by minimizing the negative log-likelihood (cross-entropy loss) on the validation set. This optimization shifts and scales the S-shaped sigmoid curve until it tightly fits the actual distribution of the validation data.
Because Platt scaling only needs to learn two parameters (\(A\) and \(B\)), it is highly efficient and resistant to overfitting. It is the ideal choice when the distortion in the model's uncalibrated outputs takes a sigmoid shape, and when the calibration dataset is relatively small.
How Isotonic Regression Works
Isotonic regression is a non-parametric calibration technique. Unlike Platt scaling, it does not assume that the relationship between the raw model scores and the true probabilities follows a specific S-shaped curve. Instead, its only constraint is that the mapping function must be isotonic (monotonically increasing). This means that if the AI model assigns a higher raw score to instance A than to instance B, the calibrated probability for A must be greater than or equal to that of B.
Isotonic regression recalibrates probabilities using the following process:
- Rank the Outputs: The uncalibrated scores from the validation set are sorted in ascending order alongside their true binary labels (0 or 1).
- Fit a Step Function: The algorithm attempts to fit a piecewise-constant, non-decreasing step function to the sorted data. It aims to minimize the mean squared error between the actual labels and the calibrated probabilities.
- Pool Adjacent Violators Algorithm (PAVA): To maintain the strict rule that probabilities cannot decrease as raw scores increase, the method uses PAVA. The algorithm scans the sorted data from left to right. Whenever it encounters a "violation"—where a higher raw score corresponds to a lower actual outcome—it pools those adjacent data points together and replaces their values with their combined average. It repeats this pooling until the entire sequence is monotonically increasing.
Because isotonic regression makes no assumptions about the underlying geometry of the calibration curve, it can correct almost any form of probability distortion. However, this flexibility comes at a cost. By fitting a complex step function, isotonic regression is prone to overfitting if the validation dataset is small. It generally requires thousands of distinct validation samples to perform reliably.
Choosing the Right Method
Both Platt scaling and isotonic regression operate strictly as post-processing steps; they do not alter the underlying weights or decision boundaries of the trained AI model, nor do they change the exact ranking of the predictions. The choice between them depends entirely on the data and the specific distortions of the base model:
- Use Platt Scaling when working with limited calibration data (fewer than 1,000 samples) or when using models like SVMs and neural networks, whose calibration errors naturally mirror a sigmoid curve.
- Use Isotonic Regression when possessing a large calibration dataset and when the base model exhibits complex, non-sigmoid distortions, which is common in Naive Bayes classifiers and random forests.