temperature calibration
**Temperature Calibration** is the **most widely used post-hoc calibration technique that applies a single learned temperature parameter T to scale model logits before the softmax function, transforming overconfident neural network predictions into well-calibrated probability estimates** — remarkable for its simplicity (one parameter fit on a validation set) and effectiveness (often matching or exceeding more complex calibration methods), making it the standard first-line approach for deploying calibrated classifiers in production.
**What Is Temperature Calibration?**
- **Mechanism**: Given raw logits $z_i$, the calibrated probability is $p_i = ext{softmax}(z_i / T)$ where $T$ is the temperature parameter.
- **T > 1**: Softens the probability distribution — reduces overconfidence by flattening peaks.
- **T < 1**: Sharpens the distribution — increases confidence in predictions.
- **T = 1**: No change — original model output.
- **Key Property**: Temperature scaling does **not change the predicted class** (argmax is preserved) — it only adjusts the confidence assigned to that prediction.
**Why Temperature Calibration Matters**
- **Simplicity**: Only one scalar parameter to optimize, requiring minimal validation data (as few as 1,000 samples).
- **Speed**: Fitting takes seconds — grid search or gradient descent on negative log-likelihood over the validation set.
- **Preservation**: The model's discriminative ability (accuracy, ranking) is completely unchanged — only the probability values shift.
- **Universality**: Works for any softmax-based classifier without model retraining.
- **Baseline Standard**: The calibration method that every other technique is benchmarked against.
**How Temperature Scaling Works**
**Step 1 — Train Model**: Train the neural network normally with cross-entropy loss. Do not modify training.
**Step 2 — Fit Temperature**: On a held-out validation set, find $T^*$ that minimizes negative log-likelihood (NLL):
$T^* = argmin_T sum_{i} -log ext{softmax}(z_i / T)_{y_i}$
**Step 3 — Apply at Inference**: For every new prediction, divide logits by $T^*$ before softmax.
**Comparison with Other Calibration Methods**
| Method | Parameters | Preserves Accuracy | Multi-class | Complexity |
|--------|-----------|-------------------|-------------|------------|
| **Temperature Scaling** | 1 | Yes | Yes | Minimal |
| **Platt Scaling** | 2 per class | Yes | Requires extension | Low |
| **Isotonic Regression** | Non-parametric | Not guaranteed | Requires binning | Medium |
| **Vector Scaling** | K×K matrix | Not guaranteed | Yes | High |
| **Dirichlet Calibration** | K² + K | Not guaranteed | Yes | High |
**Limitations and Extensions**
- **Uniform Assumption**: Assumes miscalibration is the same across all classes and confidence levels — fails when certain classes are more overconfident than others.
- **Per-Class Temperature**: Fits separate $T_k$ for each class — helps with heterogeneous miscalibration but risks overfitting.
- **Focal Temperature**: Combines temperature scaling with focal loss for training-time calibration.
- **Distribution Shift**: The optimal $T$ found on validation may not transfer to shifted test distributions — requiring recalibration or adaptive temperature methods.
Temperature Calibration is **the elegant single-knob solution for AI probability trustworthiness** — proving that the simplest approach (one parameter, no retraining, no accuracy loss) is often the most practical path from overconfident neural networks to reliable prediction systems.