The Mathematics of Confidence, Calibration and Uncertainty
An AI system gives you an answer.
It sounds certain.
It even tells you:
Confidence: 95%
Would you trust it?
Most of us instinctively interpret that number as:
“There is a 95% chance that the answer is correct.”
But that interpretation hides an important question.
Is the system’s confidence actually trustworthy?
A model can be highly confident and still be wrong.
Another model may appear less confident, but its confidence estimates may match reality much more closely.
And that difference leads us to one of the most important ideas in trustworthy Machine Learning:
Calibration.
The interesting question is not simply:
Can the model make a prediction?
It is:
Does the model know how uncertain it should be?
What Does “95% Confident” Actually Mean?
Consider a classification model.
Suppose we give it an image and it predicts:
Cat: 95%
Dog: 3%
Rabbit: 2%
The model is assigning probabilities to possible outcomes.
For the predicted class, we might write:
where (x) represents the input image.
Conceptually, the model is saying:
“Based on what I have learned, this input strongly resembles examples belonging to the class Cat.”
But there is an important distinction.
(0.95) is an estimated probability - not a guarantee.
The model does not have access to the future.
It has learned patterns from data.
Its confidence depends on those patterns, the training procedure, the model architecture and how similar the new input is to what it has seen before.
So:
High confidence does not automatically mean high reliability.
Confidence and Accuracy Are Different
Suppose a model makes 100 predictions.
For every prediction, it reports approximately:
80% confidence.
What should we expect from a well-calibrated model?
Across many comparable predictions, roughly:
80 should be correct
and:
20 should be incorrect.
This is the intuition behind calibration.
If predictions made with 80% confidence are actually correct only 55% of the time, the model is:
Overconfident.
If they are correct 95% of the time, the model may be:
Underconfident.
And if confidence and observed accuracy closely match:
The model is well calibrated.
What Is Calibration?
Calibration asks a simple but powerful question:
When a model says “80% confident,” is it actually correct about 80% of the time?
A perfectly calibrated system would satisfy approximately:
So if we collect many predictions with confidence close to:
(0.60)
we would expect roughly:
60%
of them to be correct.
For predictions near:
(0.90)
we would expect roughly:
90%
to be correct.
Calibration therefore does something very important.
It connects:
What the model believes
with:
What actually happens.
The Reliability Diagram
One of the clearest ways to study calibration is through a:
Reliability Diagram.
On the horizontal axis we place:
Predicted Confidence
and on the vertical axis:
Observed Accuracy.
A perfectly calibrated model would follow the diagonal line:
The closer the model lies to that diagonal, the more closely its confidence reflects reality.
If the curve falls substantially below the diagonal:
The model is often more confident than it should be.
If it lies above the diagonal:
The model may be more cautious than necessary.
This gives us a visual way of asking:
Can we trust the probabilities coming from the model?
A Simple Example
Imagine three models.
Model A reports an average confidence of:
90%
but its actual accuracy is only:
65%.
Model B reports:
75% confidence
and achieves:
74% accuracy.
Model C reports:
60% confidence
but achieves:
72% accuracy.
Which model has the highest confidence?
Model A.
Which model is best calibrated?
Model B.
That distinction matters.
Model A may appear impressive because it sounds very certain.
But its confidence is badly disconnected from reality.
Model B is less dramatic.
Its confidence is simply more honest.
And in many real applications, that can be much more useful.
Why Can a Model Become Overconfident?
There is no single reason.
One problem can be:
Limited training data.
If the model has not seen enough representative examples, it may make strong predictions on situations it does not truly understand.
Another problem is:
Distribution shift.
Suppose a medical imaging model was trained using images from one type of scanner.
It is then used in a hospital with different equipment.
The images may look slightly different from the training data.
The model may still produce a very confident probability.
But that confidence may no longer be reliable.
Models can also become overconfident because of:
The training objective.
A system may be trained primarily to improve predictive accuracy.
That does not automatically mean its probabilities will be perfectly calibrated.
This gives us an important distinction:
Accuracy and calibration measure different things.
A Highly Accurate Model Can Still Be Poorly Calibrated
Suppose two models both achieve:
92% accuracy.
We might assume they are equally trustworthy.
But imagine:
Model A usually predicts between 70% and 95% confidence.
Model B predicts almost everything at 99.9% confidence.
Both may achieve the same overall accuracy.
But when Model B is wrong, it is still extremely confident.
That matters if confidence is being used to decide:
- Whether to trust an answer
- Whether another test is needed
- Whether to ask a human
- Whether the system should act automatically
A model can therefore have excellent accuracy and still provide poor information about:
How much we should trust each individual prediction.
Can We Measure Calibration Mathematically?
Yes.
One commonly used idea is to divide predictions into confidence ranges.
For example:
- 50-60%
- 60-70%
- 70-80%
- 80-90%
- 90-100%
For each group, we compare:
Average confidence
with:
Actual accuracy.
A simplified calibration error can be expressed as:
Suppose one group has:
Average confidence = 90%
but:
Actual accuracy = 72%.
Then:
or:
18 percentage points.
The larger the difference, the more poorly calibrated that group is.
A common summary measure is called:
Expected Calibration Error - ECE
Conceptually:
ECE = weighted average of the gaps between confidence and accuracy.
More formally:
where (B_m) represents a group of predictions with similar confidence values.
The exact calculation is less important than the idea.
Confidence becomes meaningful only when we compare it with reality.
Another Way to Evaluate Probabilities
Suppose the true answer is represented by:
(y = 1)
and the model predicts probability:
(p = 0.90).
A simple probability-quality measure is the Brier Score:
For this prediction:
That is a small error.
Now suppose the model confidently predicts:
(p = 0.95)
but the true outcome is:
(y = 0).
Then:
The penalty is very large.
That captures something important.
Being confidently wrong should matter.
A useful probabilistic model should not only produce correct answers.
Its probabilities should also reflect how certain it ought to be.
Uncertainty Is Not Always a Weakness
Imagine two AI systems.
The first says:
“The answer is definitely A.”
Confidence:
99%
The second says:
“A appears most likely, but the evidence is ambiguous.”
Confidence:
62%
Which system is more intelligent?
We cannot answer from those statements alone.
But if the evidence really is ambiguous, the second system may be behaving far more appropriately.
This is why uncertainty should not automatically be interpreted as:
Failure.
Sometimes:
Uncertainty is information.
A system that knows when evidence is weak can behave differently from one that blindly produces high-confidence predictions.
Where Does Uncertainty Come From?
Not all uncertainty has the same source.
Sometimes the data itself is ambiguous.
Imagine a blurry medical scan or a photograph taken in poor lighting.
Even an excellent model may struggle because the information available is limited.
This is often called:
Aleatoric uncertainty.
It comes from uncertainty inherent in the observation itself.
Another form appears when the model simply does not know enough.
Perhaps it has never seen anything similar during training.
That is often called:
Epistemic uncertainty.
It arises from limited knowledge.
This distinction is useful.
One kind of uncertainty may remain even with enormous amounts of training data.
Another may decrease as the model learns from more representative examples.
What Happens When the Model Encounters Something New?
Suppose we train an image classifier on:
- Cats
- Dogs
- Horses
Then we show it:
A fox.
What should happen?
Ideally the system should recognize:
“This does not look much like the examples I learned from.”
But some models may instead confidently choose:
Dog: 92%.
The prediction is mathematically allowed.
But it may be misleading.
This problem becomes especially important when the real-world input is:
Outside the distribution of the training data.
This is often called:
Out-of-Distribution - OOD - data.
An intelligent system should not only learn:
Which answer seems most likely?
It should also help us understand:
How unfamiliar is this situation?
What About Generative AI?
Here we need to be careful.
When a traditional classification model outputs:
95%
that number may correspond to a probability produced by the model.
But when a chatbot says:
“I am 95% confident,”
that sentence should not automatically be interpreted as a calibrated 95% probability of correctness.
Generative models produce text.
A verbal statement such as:
“I’m very confident”
may itself simply be generated language.
So with generative AI, the problem becomes even more interesting.
We need methods for estimating uncertainty using signals such as:
- Probability distributions
- Agreement between repeated generations
- Agreement between different models
- Retrieval evidence
- External verification
- Specialized confidence or calibration methods
The core principle remains:
Fluency is not the same as certainty.
And certainty is not the same as correctness.
Why This Matters for AI Agents
Now connect this idea to AI agents.
An agent may need to decide whether to:
- Answer immediately
- Search for more information
- Use another tool
- Verify a calculation
- Ask the user for clarification
- Escalate the decision to a human
Confidence can influence those decisions.
Suppose an agent estimates:
Confidence = 98%.
It may decide that additional verification is unnecessary.
But suppose its confidence is:
48%.
A better strategy may be:
- Search again
- Gather more evidence
- Ask for help
- Refuse to make an unsupported conclusion
This is where uncertainty becomes part of decision-making.
The objective should not be:
Make the AI maximally confident.
The objective should be:
Make its confidence appropriately reflect what it actually knows.
Confidence Can Change the Action
Consider a medical decision-support model.
Prediction:
Condition A
Confidence:
98%.
Perhaps the system recommends:
Review result and continue with the normal clinical workflow.
Now suppose:
Confidence:
51%.
The correct action may be completely different:
- Obtain another test
- Request another image
- Ask a specialist
- Defer the decision
The prediction may be the same.
But the uncertainty changes what we should do next.
That is why confidence is not merely an extra number displayed beside a prediction.
It can become part of the decision policy.
Calibration and Human Oversight
This also explains why uncertainty matters in human-AI collaboration.
Suppose AI systems never admitted uncertainty.
Humans would receive:
Confident answer.
Confident answer.
Confident answer.
Even when the evidence was weak.
That makes it difficult to know:
When should I intervene?
A better system can distinguish between:
Routine cases
and:
Ambiguous cases.
Humans can then concentrate their attention where it is most valuable.
This is especially important in situations where errors are expensive.
Not because humans must review every AI decision.
But because good system design should help determine:
Which decisions deserve additional scrutiny?
Can Calibration Be Improved?
Yes.
Machine Learning researchers use several approaches.
One method is:
Temperature Scaling.
After a model has been trained, its output probabilities can sometimes be adjusted so they better match observed accuracy.
Other calibration approaches include techniques such as:
- Platt scaling
- Isotonic regression
- Histogram-based calibration
We can also improve reliability through:
- Better and more representative training data
- Validation on data that resembles real deployment conditions
- Monitoring for distribution shift
- Ensemble methods
- Explicit uncertainty estimation
The exact method depends on the problem.
But the goal remains the same:
Make probability estimates correspond more closely to reality.
The Mathematics Behind Trust
This brings together several mathematical ideas.
We begin with probability:
We compare predictions with actual outcomes.
We study:
- Accuracy
- Confidence
- Calibration error
- Probability scores
- Uncertainty
And eventually we use those quantities to make decisions.
So the mathematics is not simply describing the prediction.
It is helping us answer another question:
How much should we trust the prediction?
Accuracy Answers One Question. Calibration Answers Another.
Accuracy asks:
How often is the model correct?
Calibration asks:
When the model says it is 90% confident, is it really correct about 90% of the time?
Those are not the same question.
And a trustworthy AI system needs us to think about both.
This is especially important as AI moves from:
Making predictions
to:
Taking actions.
Because once an AI system begins choosing tools, allocating resources, recommending treatments, interacting with users or acting autonomously, uncertainty becomes part of the decision itself.
The Bigger Lesson
We often think intelligence means:
Knowing the answer.
But perhaps another form of intelligence is:
Knowing when the answer is uncertain.
A system that recognizes the limits of its knowledge can:
- Search again
- Ask for more information
- Request help
- Verify its conclusion
- Wait before acting
That does not make the system weaker.
In many situations, it makes the system:
More reliable.
The Takeaway
When an AI system says:
“95% confident,”
do not immediately read that as:
“95% certain to be correct.”
Ask instead:
- Is the system well calibrated?
- Do its probability estimates match its actual performance?
- Does it become less confident when situations are unfamiliar?
- Can it recognize ambiguous evidence?
- Can uncertainty change what it decides to do next?
Those questions take us beyond:
“Can AI produce an answer?”
toward a much more important question:
“Does AI know when its answer should be trusted?”
Learning with Purpose
At The Learning Studio, I approach Mathematics, Data Science, Machine Learning and Artificial Intelligence by connecting the mathematics to the behaviour we actually observe in intelligent systems.
Probability is not simply:
A formula in a textbook.
Calibration is not simply:
Another evaluation metric.
Uncertainty is not simply:
A statistical inconvenience.
Together they help us understand:
- When predictions are reliable
- When models should hesitate
- When another source is needed
- When a human should become part of the decision
The learning journey becomes:
Concept -> Intuition -> Mathematics -> Model Behaviour -> Experiment -> Question
Because understanding AI is not only about knowing how a model produces an answer.
It is also about understanding when that answer deserves our confidence.
Coming Next
Why Can Two AI Models See the Same Data and Disagree?
Two models receive the same information.
One says:
Answer A.
The other says:
Answer B.
Which one should we trust?
Does disagreement mean one model is wrong?
Or can disagreement itself tell us something important about:
- Uncertainty
- Bias
- Data
- Model assumptions
- The limits of what can actually be known
In the next article, we will explore:
Why disagreement between AI systems may sometimes be information rather than failure.