Course outline

Deep Learning / Representation and acceptance evidence / Lesson 14

Calibration, shift, and robustness

Evaluate confidence and failure slices separately from top-line correctness.

About 4 min readContent reviewed
On this page

Lesson goals

  • Distinguish calibration from accuracy.
  • State the scope of temperature scaling.
  • Design robustness checks for plausible input changes.

Confidence and correctness answer different questions

Accuracy measures how often a decision matches an observed target under a defined sample and threshold. Calibration concerns whether probability statements align with observed frequencies under an appropriate distribution. A classifier can be accurate yet overconfident, or calibrated at an uninformative base rate while discriminating poorly. Class order, label quality, and selection of evaluated examples affect both. Begin by defining which probability is being assessed: the predicted class confidence, one named class probability, or a decision-specific risk. These are related but different calibration questions and should not be combined under an unexplained single number.

Interpret a reliability calculation with its sample size

The first fixture collects four predicted-class confidences in one bin and compares their mean with correctness frequency. The gap is large under this invented sample, but the sample is far too small to establish a population property. Real reliability diagrams depend on binning, and an aggregate error can conceal opposite errors in different classes or groups. Include counts, proper scoring rules such as log loss, and uncertainty suited to the observation dependencies. Do not tune bins until the desired visual conclusion appears. A calibration set used to fit a correction is another learned-data boundary.

python Deterministic standard-library calculation
probabilities = [0.9, 0.9, 0.9, 0.9]
correct = [1, 1, 0, 0]
print(f"confidence={sum(probabilities)/len(probabilities):.2f}")
print(f"accuracy={sum(correct)/len(correct):.2f}")
print(f"bin gap={abs(sum(probabilities)/4-sum(correct)/4):.2f}")
Expected output
confidence=0.90
accuracy=0.50
bin gap=0.40

One synthetic confidence bin illustrates overconfidence; four examples cannot establish population calibration.

Temperature scaling changes probabilities not evidence

Dividing multiclass logits by one positive temperature preserves their ordering and therefore their argmax. The second fixture shows a softer probability at temperature two for fixed logits. Fitting temperature requires separate permitted calibration data and a specified objective; this program merely demonstrates the transformation. A fitted temperature can improve measured calibration in some settings but does not guarantee it for every class, subgroup, or shifted distribution. If deployment uses a probability threshold rather than argmax, decisions can change. Record the transformed score contract and reassess threshold behavior explicitly.

python Deterministic standard-library calculation
from math import exp
logits = [4.0, 1.0]
for temperature in [1.0, 2.0]:
    scaled = [z/temperature for z in logits]
    m = max(scaled)
    denominator = sum(exp(z-m) for z in scaled)
    p = [exp(z-m)/denominator for z in scaled]
    print(f"T={temperature:.1f}, p0={p[0]:.6f}, class={max(range(2), key=lambda i:p[i])}")
Expected output
T=1.0, p0=0.952574, class=0
T=2.0, p0=0.817574, class=0

A shared positive temperature softens these probabilities while preserving argmax; the temperature was not fitted.

Robustness is relative to a stated change

A robustness test specifies the allowed perturbation, its size or distribution, and the task property expected to survive. Small numeric noise, image brightness changes, missing features, and a changed population are different tests. A label-preserving change in one application can change the true target in another. Evaluate relevant slices and compare a baseline under the same conditions, without turning a synthetic stress fixture into a claim of real-world security or reliability. Distribution shift can affect inputs, class prevalence, or relationships between inputs and targets; unlabeled input summaries alone cannot reveal every resulting performance change.

Make abstention and reassessment explicit

An abstention or human-review rule can reduce automatic coverage while changing the error profile of the accepted set. Report both coverage and accepted-set performance, and inspect who is excluded. High softmax confidence does not guarantee that an input belongs to the training distribution, so a maximum-score threshold is not a universal out-of-distribution detector. Preserve a fallback policy for invalid or unsupported inputs and define what evidence triggers reassessment. The lesson fixtures calculate fixed probabilities and counts only; they make no certification, safety guarantee, or external robustness benchmark claim.

Common errors and fixes

High accuracy is reported as calibrated confidence

Why it happens
Decision correctness was substituted for probability reliability.
How to fix it
Assess confidence frequencies and proper scoring rules separately.
Prevent it next time
State the exact calibration question and evaluated population.

Temperature is fitted on final-test labels

Why it happens
Assessment data influenced the probability mapping.
How to fix it
Fit on permitted calibration data and protect final assessment.
Prevent it next time
Track the data boundary for every post-processing step.

A confidence threshold is treated as universal novelty detection

Why it happens
A high score was assumed to prove a familiar input.
How to fix it
Evaluate the detection policy against relevant unsupported cases.
Prevent it next time
Report coverage, failure slices, and known limitations.

Check your understanding

1. Can a positive shared temperature change multiclass argmax? Can it change a probability-threshold decision?

Show worked solution

It preserves logit ordering, so argmax is unchanged except implementation-level ties or numerical behavior. It changes probabilities, so a threshold such as 0.9 can be crossed. The fixture changes class-zero confidence from about 0.953 to 0.818, crossing that threshold without changing argmax.

2. An abstaining model reports 99% accuracy on 10% of inputs. What is missing?

Show worked solution

Report the 10% coverage, how the other 90% are handled, accepted-set sample counts and uncertainty, and subgroup coverage and errors. Compare the combined decision process with the intended baseline. A selective accuracy alone does not describe overall usefulness or equitable access.

Key takeaways

  • Calibration, discrimination, coverage, and robustness are separate properties.
  • Post-processing needs its own honest fitting boundary.
  • Confidence is evidence to assess, not a universal guarantee.

Official references