Machine learning models are often used to predict probabilities.
A model might say:
- There is a 90% probability that a customer will churn.
- There is a 75% probability that a transaction is fraudulent.
- There is a 20% probability that a loan applicant will default.
- There is a 95% probability that an image contains a particular object.
These numbers can look precise.
But there is an important question:
Do the predicted probabilities actually reflect what happens in the real world?
If a machine learning model predicts 0.80 probability for a group of 100 cases, we would ideally expect roughly 80 of those cases to belong to the positive class.
When predicted probabilities correspond well with observed outcomes, the model is said to be well calibrated.
This concept is known as probability calibration.
Probability calibration is particularly important when businesses use model probabilities to make decisions rather than simply assigning observations to classes.
In this article, we’ll explore what probability calibration means, why it matters, how to identify poorly calibrated models, and how to calibrate machine learning models using Python and scikit-learn.
What Is Probability Calibration?
Probability calibration measures how closely a model’s predicted probabilities match the actual frequency of an outcome.
Suppose a binary classification model predicts whether customers will cancel a subscription.
The model gives 100 customers a predicted churn probability of approximately 0.70.
If the model is well calibrated, we would expect around 70 of those customers to actually churn.
If only 40 customers churn, the model is overconfident.
If 90 customers churn, the model is underconfident.
The key idea can be summarized as:
Among predictions made with probability p, approximately p proportion should experience the outcome.
For a perfectly calibrated model:
[
P(Y=1 \mid \hat{P}=p) = p
]
Where:
- (Y=1) represents the positive outcome.
- (\hat{P}) is the model’s predicted probability.
- (p) is the predicted probability value.
In practical machine learning, perfect calibration is rare, but a model can still be considered reasonably calibrated if predicted probabilities closely correspond to observed frequencies.
Calibration Is Different From Classification Accuracy
One of the most important things to understand is that calibration and accuracy measure different properties of a model.
Consider two models predicting whether a customer will churn.
Model A
Customer A → 0.95
Customer B → 0.90
Customer C → 0.85
Customer D → 0.80
Model B
Customer A → 0.62
Customer B → 0.58
Customer C → 0.55
Customer D → 0.51
A model can be good at ranking customers by risk while producing poorly calibrated probabilities.
For example, suppose the highest-risk customers consistently appear at the top of the list.
That can make the model useful for ranking even if its probability estimates are too high.
This leads to an important distinction:
| Model property | Main question |
|---|---|
| Accuracy | How often are predictions correct? |
| Precision | How many predicted positives are actually positive? |
| Recall | How many actual positives did the model identify? |
| Ranking | Can the model order observations by risk? |
| Calibration | Do predicted probabilities match observed frequencies? |
A model can perform well on one dimension and poorly on another.
A Simple Calibration Example
Imagine a fraud detection model produces these predictions:
| Predicted probability | Number of transactions | Actual frauds |
|---|---|---|
| 0.10 | 100 | 9 |
| 0.30 | 100 | 31 |
| 0.50 | 100 | 48 |
| 0.70 | 100 | 69 |
| 0.90 | 100 | 91 |
These predictions are reasonably calibrated.
For example, among transactions predicted at 0.90 probability, about 91% were actually fraudulent.
The model’s predictions are close to observed outcomes.
Now imagine another model:
| Predicted probability | Number of transactions | Actual frauds |
|---|---|---|
| 0.10 | 100 | 2 |
| 0.30 | 100 | 12 |
| 0.50 | 100 | 25 |
| 0.70 | 100 | 42 |
| 0.90 | 100 | 60 |
This model is systematically overconfident.
It predicts high probabilities much more frequently than the observed fraud rate justifies.
The model may still rank fraudulent transactions relatively well.
But its probabilities cannot be interpreted literally.
Why Probability Calibration Matters
Calibration becomes especially important when the predicted probability itself influences a decision.
Consider a hospital using a model to estimate the probability that a patient will develop a particular condition.
A prediction of:
0.51
and a prediction of:
0.95
should not be treated as merely different class labels.
They communicate different levels of risk.
The same applies to:
- Credit risk
- Fraud detection
- Customer churn
- Insurance claims
- Demand forecasting
- Medical risk prediction
- Marketing response prediction
- Predictive maintenance
- Loan default prediction
If a business interprets a probability as a real-world likelihood, calibration becomes important.
When Calibration Matters Less
Calibration isn’t equally important for every machine learning application.
Suppose you only need to rank customers from highest to lowest likelihood of churn.
You might use:
Customer A → 0.91
Customer B → 0.78
Customer C → 0.64
Customer D → 0.32
Even if the probabilities aren’t perfectly calibrated, the ordering may still be useful.
If the only requirement is:
“Which customers should the retention team contact first?”
then ranking performance may matter more than whether 0.91 literally means a 91% chance.
However, if the business says:
“Contact every customer whose probability of churn is at least 70%.”
then calibration becomes much more important.
The organization is now interpreting the probability as a meaningful risk estimate.
Calibration vs Classification Threshold
Probability calibration is also closely related to classification thresholds.
Suppose a model produces:
Customer A → 0.82
Customer B → 0.64
Customer C → 0.41
Customer D → 0.17
Using a threshold of 0.50 gives:
A → Positive
B → Positive
C → Negative
D → Negative
But the threshold does not make the probabilities calibrated.
A threshold simply converts probabilities into class predictions.
Calibration asks a different question:
Does a predicted probability of 0.70 correspond to an outcome frequency of approximately 70%?
This distinction is important.
You can have:
- A well-calibrated model with a poorly chosen threshold.
- A poorly calibrated model with a useful threshold.
- A model that is well calibrated but has poor discrimination.
- A model with excellent discrimination but poor calibration.
These are separate properties.
How to Check Probability Calibration
One common method is a calibration curve, also called a reliability diagram.
The basic process is:
- Generate predicted probabilities.
- Group predictions into probability bins.
- Calculate the average predicted probability in each bin.
- Calculate the actual proportion of positive outcomes in each bin.
- Compare the two values.
For example:
| Average predicted probability | Actual positive rate |
|---|---|
| 0.10 | 0.09 |
| 0.30 | 0.28 |
| 0.50 | 0.47 |
| 0.70 | 0.74 |
| 0.90 | 0.88 |
These values are relatively close.
A calibration plot visualizes the same information.
The ideal calibration line is:
[
y=x
]
Predictions close to this line indicate better calibration.
Calibration Curve in Python
Scikit-learn provides tools for evaluating and visualizing probability calibration.
Here is a simple example using logistic regression:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.calibration import CalibrationDisplay
X, y = make_classification(
n_samples=5000,
n_features=10,
random_state=42
)
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
test_size=0.3,
random_state=42
)
model = LogisticRegression()
model.fit(X_train, y_train)
CalibrationDisplay.from_estimator(
model,
X_test,
y_test,
n_bins=10
)
The resulting calibration plot compares predicted probabilities with observed outcome frequencies.
A curve close to the diagonal represents better calibration.
What Does an Uncalibrated Model Look Like?
There are several common patterns.
Overconfident model
An overconfident model tends to predict probabilities that are too extreme.
For example:
Predicted → 0.90
Observed → 0.65
The model believes the event is much more likely than it actually is.
Underconfident model
An underconfident model may produce:
Predicted → 0.60
Observed → 0.80
The model is assigning too little probability to the event.
Poorly calibrated extremes
A model can also produce probabilities concentrated around values such as:
0.01
0.99
while the actual outcomes are much less predictable.
This is another indication that the probabilities may not be reliable.
Common Calibration Methods
If a model is poorly calibrated, a calibration method can be applied to transform its raw probabilities into better-calibrated estimates.
Two commonly used approaches are:
- Platt scaling
- Isotonic regression
Scikit-learn also supports a broader calibration framework through CalibratedClassifierCV.
Platt Scaling
Platt scaling applies a logistic transformation to the model’s output.
The general idea is:
Original model output
↓
Logistic transformation
↓
Calibrated probability
It is relatively simple and often works well when the relationship between the model’s scores and actual probabilities is reasonably smooth.
In scikit-learn, you can use:
from sklearn.calibration import CalibratedClassifierCV
calibrated_model = CalibratedClassifierCV(
model,
method="sigmoid",
cv=5
)
calibrated_model.fit(X_train, y_train)
probabilities = calibrated_model.predict_proba(X_test)[:, 1]
The sigmoid method corresponds to the Platt scaling approach.
Isotonic Regression
Isotonic regression is a non-parametric calibration method.
Instead of assuming a particular mathematical shape, it learns a monotonic relationship between the original predictions and observed outcomes.
Conceptually:
Raw probability
↓
Isotonic calibration
↓
Adjusted probability
In scikit-learn:
calibrated_model = CalibratedClassifierCV(
model,
method="isotonic",
cv=5
)
calibrated_model.fit(X_train, y_train)
probabilities = calibrated_model.predict_proba(X_test)[:, 1]
Isotonic regression can be flexible, but that flexibility can become a problem with small datasets.
With limited calibration data, it can overfit.
Platt Scaling vs Isotonic Regression
| Feature | Platt Scaling | Isotonic Regression |
|---|---|---|
| Method | Parametric | Non-parametric |
| Flexibility | Lower | Higher |
| Data requirement | Generally lower | Generally higher |
| Overfitting risk | Lower | Higher with small datasets |
| Assumption | Sigmoid relationship | Monotonic relationship |
| Common use | Smaller datasets | Larger calibration datasets |
The choice depends on the model, dataset, and amount of calibration data available.
Why You Should Not Calibrate on the Test Set
This is an important machine learning practice.
Suppose you train your model using:
Training set
and then calibrate it using:
Test set
You have now used the test set to influence the model.
That compromises the purpose of the test set.
The test set should ideally remain untouched until final evaluation.
A better setup is:
Full dataset
↓
Training data
↓
Model fitting
Calibration data
↓
Probability calibration
Test data
↓
Final evaluation
Cross-validation can also be used to make calibration more robust while reducing the risk of leakage.
Scikit-learn’s CalibratedClassifierCV is designed to support cross-validation-based calibration.
Calibration With Different Machine Learning Models
Different algorithms can behave differently when producing probabilities.
Logistic Regression
Logistic regression often produces reasonably calibrated probabilities when its assumptions and data conditions are appropriate.
However, it is not automatically perfectly calibrated.
Decision Trees
Individual decision trees can produce poorly calibrated probabilities, particularly when they create small or highly specific leaf nodes.
Random Forests
Random forests can produce useful probability estimates but may still require calibration depending on the application.
Gradient Boosting
Boosting models can produce highly discriminative predictions while their probability estimates may require calibration.
Neural Networks
Neural networks can also be overconfident, particularly when trained on complex classification problems.
The important lesson is:
Good classification performance does not automatically guarantee good probability calibration.
Metrics for Evaluating Calibration
A calibration curve provides a visual assessment, but numerical metrics can also be useful.
Brier Score
The Brier score measures the mean squared difference between predicted probabilities and actual binary outcomes.
For binary classification:
[
BS = \frac{1}{N}\sum_{i=1}^{N}(p_i-y_i)^2
]
Where:
- (p_i) is the predicted probability.
- (y_i) is the actual outcome.
- (N) is the number of observations.
Lower values indicate better probabilistic predictions.
In Python:
from sklearn.metrics import brier_score_loss
score = brier_score_loss(
y_test,
probabilities
)
print(score)
However, Brier score is influenced by more than calibration alone. It can also reflect how well the model separates different outcomes.
Therefore, it should not be treated as a pure calibration metric.
Expected Calibration Error
Another commonly discussed metric is Expected Calibration Error, or ECE.
The idea is to divide predictions into bins and compare:
Average predicted probability
with:
Observed frequency
for each bin.
Conceptually:
[
ECE = \sum_{b=1}^{B}\frac{n_b}{N}
|\text{accuracy}_b-\text{confidence}_b|
]
Where each bin represents a group of predictions with similar confidence.
Lower ECE generally indicates better agreement between predicted confidence and observed outcomes.
However, ECE depends on choices such as the number and type of bins, so it should be interpreted carefully rather than treated as an absolute measure of model quality.
Calibration Is Especially Important for Imbalanced Data
Imagine a fraud detection problem where only 1% of transactions are fraudulent.
A model may produce:
Fraud probability = 0.01
for many transactions.
Even small calibration errors can matter when the probabilities are used for financial decisions.
For example, suppose the actual fraud rate among a particular group is 2%, but the model consistently predicts 5%.
That difference might look small.
But when applied to millions of transactions, the resulting decisions could have significant consequences.
Calibration therefore deserves particular attention in low-prevalence problems where probabilities are used operationally.
Common Mistakes With Probability Calibration
Mistake 1: Assuming high accuracy means good calibration
A model can have high classification accuracy while producing unreliable probabilities.
Mistake 2: Treating the 0.50 threshold as universal
A probability of 0.50 is not automatically the correct decision threshold.
Mistake 3: Calibrating using the test set
This can introduce leakage and make final evaluation unreliable.
Mistake 4: Using too little calibration data
Flexible calibration methods can overfit small datasets.
Mistake 5: Looking at only one metric
Use calibration curves alongside appropriate numerical metrics and the model’s actual business requirements.
Mistake 6: Ignoring dataset shift
A model can be well calibrated on historical data and become poorly calibrated when the underlying population changes.
Calibration Can Change Over Time
Suppose a model was trained in 2025.
At the time:
Predicted probability = 0.70
Actual event rate = 0.69
The model was reasonably calibrated.
A year later, customer behavior changes.
Now:
Predicted probability = 0.70
Actual event rate = 0.52
The model’s calibration has deteriorated.
This can happen because of:
- Changes in customer behavior
- Economic conditions
- New products
- Changes in business processes
- Data pipeline changes
- Changes in the target population
- Policy changes
- Concept drift
Therefore, calibration should sometimes be monitored after deployment rather than treated as a one-time preprocessing step.
A Practical Calibration Workflow
A useful workflow looks like this:
1. Define the prediction problem
↓
2. Train the model
↓
3. Generate probability predictions
↓
4. Evaluate discrimination
↓
5. Evaluate calibration
↓
6. Choose a calibration method if necessary
↓
7. Calibrate using appropriate validation data
↓
8. Evaluate on untouched test data
↓
9. Monitor calibration after deployment
This approach prevents calibration from becoming an afterthought.
When Should You Calibrate a Model?
Calibration is especially worth considering when:
- Probabilities are directly used for decisions.
- Risk scores are communicated to users.
- Different actions correspond to different risk levels.
- The model’s raw probabilities appear overconfident or underconfident.
- A downstream system consumes predicted probabilities.
- You need reliable estimates of expected event rates.
It may be less important when the model is primarily being used to rank observations and the exact probability values are not interpreted.
Probability calibration answers a simple but important question:
When a machine learning model says something has a 70% probability of happening, does it actually happen about 70% of the time among similar predictions?
A model can be highly accurate and still have poorly calibrated probabilities.
It can also rank observations effectively while producing probabilities that should not be interpreted literally.
This distinction matters because probabilities often become inputs to real decisions.
Calibration methods such as Platt scaling and isotonic regression can improve probability estimates, while tools such as calibration curves, Brier scores, and Expected Calibration Error can help evaluate them.
Most importantly, calibration should be treated as part of the model evaluation and deployment process rather than simply an optional final adjustment.
For applications where probability itself carries meaning, a model should not only tell you what is likely to happen.
It should also provide a probability that you can reasonably trust.
Frequently Asked Questions
1. What is probability calibration in machine learning?
Probability calibration is the process of making predicted probabilities correspond more closely to observed outcome frequencies. A well-calibrated model predicting 0.70 for a group of observations should see the positive outcome occur approximately 70% of the time in that group.
2. What is a calibration curve?
A calibration curve compares predicted probabilities with the actual proportion of positive outcomes. A perfectly calibrated model would follow the diagonal line where predicted probability equals observed frequency.
3. What is the difference between calibration and accuracy?
Accuracy measures how often a model’s final class predictions are correct. Calibration measures whether the model’s predicted probabilities correspond to actual outcome frequencies. A model can have good accuracy but poor calibration.
4. What are the main methods for probability calibration?
Two widely used methods are Platt scaling, also called sigmoid calibration, and isotonic regression. Platt scaling is simpler and generally works well with less calibration data, while isotonic regression is more flexible but can overfit when the calibration dataset is small.
5. Should I calibrate my machine learning model?
Calibration is particularly useful when predicted probabilities are used directly for decisions, risk estimation, resource allocation, or threshold-based actions. If the model is only used to rank observations, calibration may be less important than ranking performance.