Advanced Machine Learning

20: Model Comparison & Calibration

Schedule (you are here )

# date topic description
124-Aug-2026Introduction
226-Aug-2026Foundations of learningDrop/Add
331-Aug-2026PAC learnabilityHW1
402-Sep-2026Linear learning models
507-Sep-2026Labor Day HolidayHoliday
609-Sep-2026Principal Component AnalysisProject ideas
714-Sep-2026Curse of DimensionalityHW2, HW1 due
816-Sep-2026Bayesian Decision Theory
921-Sep-2026Parameter estimation: MLE
1023-Sep-2026Parameter estimation: MAP & NBfinalize teams
1128-Sep-2026Logistic RegressionHW3, HW2 due
1230-Sep-2026Kernel Density Estimation
1305-Oct-2026Support Vector Machines
1407-Oct-2026Matrix Factorization
1512-Oct-2026* MidtermExam, HW3 due
1614-Oct-2026k-means clustering
1719-Oct-2026Invited: Intro to Causal Learning I
# date topic description
1821-Oct-2026Invited: Intro to Causal Learning II
1926-Oct-2026* Mid-point projects checkpointHW4, P
2028-Oct-2026Expectation Maximization
2102-Nov-2026Stochastic Gradient Descent
2204-Nov-2026Automatic Differentiation
2309-Nov-2026Nonlinear embedding approachesHW5, HW4 due
2411-Nov-2026Model comparison & calibration
2516-Nov-2026Convolutional Neural Networks
2618-Nov-2026Word Embedding
2723-Nov-2026Thanksgiving BreakHoliday
2825-Nov-2026Thanksgiving BreakHoliday
2930-Nov-2026* Final ExamExam
3002-Dec-2026Project Final PresentationsHW5 due, P
3107-Dec-2026No classClasses End
3216-Dec-2026Project Reportsdue
3317-Dec-2026Grades due 5 p.m.PAWS

Outline for the lecture

  • Bias-Variance Trade-off & No Free Lunch Theorem
  • Problems with Accuracy (Imbalance & Rebalancing Paradox)
  • Confusion Matrix, Visual Quotients, Balanced Accuracy & $F_1$
  • Cross-Validation, Hyperparameter Search & Expected Profit
  • Profit Curves, ROC / AUC & Model Calibration

Bias-variance trade off revisited

Bias-Variance Decomposition for MSE

  • MSE as an error measure
  • $E\left[ (\hat{\theta} - \theta)^2 \right]$
  • $= E\left[ \hat{\theta}^2 - 2 \hat{\theta}\theta + \theta^2\right]$
  • $= E\left[ \hat{\theta}^2\right] - 2 E\left[\hat{\theta}\right] \theta + \theta^2$
  • Add and subtract $E\left[ \hat{\theta} \right]^2$
  • \begin{align} = & E\left[ \hat{\theta} \right]^2 - 2 E\left[\hat{\theta}\right] \theta + \theta^2 \\ & + E\left[ \hat{\theta}^2\right] - E\left[ \hat{\theta} \right]^2 \end{align}
  • \begin{align} = & \underbrace{(E\left[ \hat{\theta} \right] - \theta)^2}_{\text{Bias}^2} + \underbrace{E\left[ \hat{\theta}^2\right] - E\left[ \hat{\theta} \right]^2}_{\text{Variance}} \end{align}
  • Is not variance $E\left[ (\hat{\theta} - E\left[\hat{\theta}\right])^2\right]$?
  • $E\left[ (\hat{\theta} - E\left[\hat{\theta}\right])^2\right]$
  • $= E\left[ \hat{\theta}^2 - 2\hat{\theta}E\left[\hat{\theta}\right] + E\left[\hat{\theta}\right]^2 \right]$
  • $= E\left[ \hat{\theta}^2 \right] - 2 E\left[ \hat{\theta}\right]E\left[\hat{\theta}\right] + E\left[\hat{\theta}\right]^2$
  • $= E\left[ \hat{\theta}^2 \right] - 2 E\left[\hat{\theta}\right]^2 + E\left[\hat{\theta}\right]^2$
  • $= E\left[ \hat{\theta}^2 \right] - E\left[\hat{\theta}\right]^2$

Bias-variance tradeoff

bias variance

If data is all we have, how do we know which model is better?

split

Training Error Lies: 100 Random Dataset Splits

bias variance
Each thin hairline is one random dataset draw $\CD_i$ (vertical spread = Variance). As complexity grows, training error $\downarrow$ monotonically while test error $\uparrow$ and fans out — never select model complexity on training error!

Select a Model That Generalizes Best

We pick hyperparameter $\hat{\theta}_i = \argmin_{\theta} g(\theta; \CD_i)$ by minimizing validation error $g(\theta; \CD_i)$ to approximate true test error $G(\theta)$:
$\EE_{\CD}\!\left[(g(\theta; \CD) - G(\theta))^2\right] = \text{Bias}(g)^2 + \text{Variance}(g)$
True test error G(θ) Pointwise Mean 𝔼[g(θ; 𝒟)] Splits g(θ; 𝒟ᵢ) & minima θ̂ᵢ 1. Unbiased, High Variance Mean optimum 𝔼[θ̂] = θ* (3 left, 3 right), but high variance scatters θ̂ᵢ! Error Rate Hyperparameter θ (e.g., kernel width / regularization) θ* = 𝔼[θ̂] (No Bias) High Variance: individual θ̂ᵢ scatter widely on both sides of θ*! 2. Biased, Low Variance Mean optimum 𝔼[θ̂] ≠ θ* (shifted horizontally), but splits 𝒟ᵢ cluster tightly! Hyperparameter θ (e.g., kernel width / regularization) Bias: 𝔼[θ̂] − θ* ≠ 0 θ* 𝔼[θ̂] Low Variance: all θ̂ᵢ stay close to θ* (never far off!)
Takeaway: A small bias ($\EE[\hat{\theta}] \neq \theta^*$) with low variance stays consistently near $\theta^*$, whereas an unbiased estimator with high variance can pick disastrous $\hat{\theta}_i$ far from $\theta^*$!

From Classical Bias-Variance to Double Descent

Classical Under-Parameterized Regime (p < n) under-fitting over-fitting Risk / Error Capacity of ℋ (Parameters p) Bias² Variance Training risk Test risk Optimal Sweet Spot Modern Over-Parameterized Regime (p ≫ n) “modern” interpolating regime (Training risk = 0) Interpolation Threshold (p = n) Second Descent (Test risk < Sweet Spot!)
Why the Second Descent? At $p = n$, the unique interpolant has exploding norm $\|\hat{\vth}\|_2 \sim \sigma_{\min}(\vec{X})^{-1} \to \infty$. For $p \gg n$, SGD finds the minimum-norm interpolant $\hat{\vth}_{\text{min}} = \argmin_{\vec{X}\vth = \vec{y}} \|\vth\|_2^2 = \vec{X}^{\top}(\vec{X}\vec{X}^{\top})^{-1}\vec{y}$, whose norm and variance shrink as $p$ grows!

No free lunch theorem

remote
cats and mice
"Even after the observation of the frequent conjunction of objects, we have no reason to draw any inference concerning any object beyond those of which we have had experience."

David Hume, in A Treatise of Human Nature, Book I, part 3, Section 12.

David Wolpert
wolperts

No free lunch theorem (simply put)

There is not a universally good algorithm that's best on all possible test data!

Problems with accuracy

Accuracy on a Skewed Dataset (95% vs. 5%)

$$\text{accuracy} = \frac{\text{number of correct predictions}}{\text{number of total predictions}}$$
Dataset (N = 10⁶) d X 1 N y {0,1} Class Split in the Wild Class 0 (5%) Class 1 (95%) 10% error on each class has asymmetric impact: • 10% error on Class 0 (5%) → loses only 0.5% total accuracy • 10% error on Class 1 (95%) → loses 9.5% total accuracy! Trivial Rule: ∀ x, predict 1 ⇒ 95% Accuracy! Only 5% error — but 100% of rare Class 0 (e.g., disease) is missed!

Naive Fix: Manually Rebalance Training Data (50% / 50%)

Suppose $N = 10^6$. Take all $5\%$ of Class $0$ ($50{,}000$) + $5\%$ from Class $1$ ($50{,}000$) $\implies 10^5$ balanced samples:
Rebalanced (100k) Class 0 50% (50k) Class 1 50% (50k) Classifier A 0 (100%) all 0s correct 0 (17% err) 1 (83%) Classifier B 0 (80%) 1 (20% err) 1 (100%) all 1s correct On 50% / 50% Split: ACC(A) = 91.5% ≈ 92% (0.5 × 100% + 0.5 × 83%) ACC(B) = 90.0% (0.5 × 80% + 0.5 × 100%) ⇒ We pick Winner A!

The Rebalancing Paradox: What Happens in the Wild?

Now deploy both classifiers on the true population ($5\%$ Class $0$, $95\%$ Class $1$):
"Winner" Classifier A ($92\%$ on balanced):
• Class $0$ ($5\%$): $100\%$ correct
• Class $1$ ($95\%$): $83\%$ correct
$$\text{ACC}_{\text{wild}}(A) = 0.05(1) + 0.95(0.83) \approx \color{#dc322f}{\mathbf{84\%}}$$
"Loser" Classifier B ($90\%$ on balanced):
• Class $0$ ($5\%$): $80\%$ correct
• Class $1$ ($95\%$): $100\%$ correct
$$\text{ACC}_{\text{wild}}(B) = 0.05(0.80) + 0.95(1) = \mathbf{99\%}$$

Neither $84\%$ nor $99\%$ makes sense without knowing the cost of mistaking $0 \to 1$ vs. $1 \to 0$!

Confusion Matrix

Two-Class Confusion Matrix

True Class p n Predicted Class P N True Positives (TP) False Positives (FP) False Negatives (FN) True Negatives (TN) Confusion Matrix
  • Columns ($\mathbf{p}, \mathbf{n}$): True ground-truth class.
  • Rows ($\mathbf{P}, \mathbf{N}$): Classifier predicted class.
  • Main diagonal ($\text{TP}, \text{TN}$): Correct decisions.
  • Off-diagonal ($\text{FP}, \text{FN}$): Two distinct types of mistakes (ideally $0$, but in practice a trade-off!).

Statistician view of the world

Pregnant

Visual Quotient Mnemonic: Accuracy

Accuracy (ACC) Main Diagonal (TP + TN) ÷ All 4 Cells Numerator pnPNTPFPFNTN = (TP + TN) / All Divided by pnPNTPFPFNTN
$$\text{ACC} = \frac{\text{TP} + \text{TN}}{\text{TP} + \text{FP} + \text{FN} + \text{TN}}$$ When $\text{TN}$ is huge, it dominates both the numerator and denominator!

Family 1: Sensitivity & Specificity (Column Quotients)

Sensitivity / Recall (TPR) Top-Left (TP) ÷ True Positive Column (p) Numerator pnPNTPFPFNTN = TP / (TP + FN) Divided by pnPNTPFPFNTN Specificity (TNR) Bottom-Right (TN) ÷ True Negative Column (n) Numerator pnPNTPFPFNTN = TN / (FP + TN) Divided by pnPNTPFPFNTN

Family 2: Precision & Recall (Information Retrieval)

Precision (PPV) Top-Left (TP) ÷ Predicted Positive Row (P) Numerator pnPNTPFPFNTN = TP / (TP + FP) Divided by pnPNTPFPFNTN Recall (= Sensitivity) Top-Left (TP) ÷ True Positive Column (p) Numerator pnPNTPFPFNTN = TP / (TP + FN) Divided by pnPNTPFPFNTN

Why One Metric Is Not Enough: How Models Cheat

  • Maximize Recall (Sensitivity) alone?
    Predict Positive ($\mathbf{P}$) for everything $\implies \text{FN} = 0 \implies \mathbf{100\%\text{ Recall}}$ (with massive $\text{FP}$!).
  • Maximize Specificity alone?
    Predict Negative ($\mathbf{N}$) for everything $\implies \text{FP} = 0 \implies \mathbf{100\%\text{ Specificity}}$ (catches $0$ positives!).
  • Maximize Precision alone?
    Set threshold ultra-high and predict $\mathbf{P}$ on only $1$ certain sample $\implies \mathbf{100\%\text{ Precision}}$!

We must combine complementary quotients so the classifier cannot cheat!

Imbalanced Example: Raw Accuracy Rewards Ignoring P

Pred \ True $\mathbf{p}$ $\mathbf{n}$
$\mathbf{P}$ $5$ $50$
$\mathbf{N}$ $10$ $10{,}000$
1. Our Classifier's Accuracy: $$\text{acc} = \frac{5 + 10{,}000}{10 + 5 + 50 + 10{,}000} = \mathbf{99.4\%}$$
2. Dummy "Predict All $\mathbf{N}$" ($\text{TP}=0, \text{FP}=0$): $$\text{acc}_{\text{all-}N} = \frac{0 + 10{,}050}{15 + 10{,}050} \approx \color{#dc322f}{\mathbf{99.9\% > 99.4\%!}}$$

Balanced Accuracy & F1 Score Catch the Cheater

Balanced Accuracy ($\text{BA}$): $$\text{BA} = \frac{\text{Sensitivity} + \text{Specificity}}{2}$$
• Our model ($\begin{smallmatrix}5 & 50\\ 10 & 10000\end{smallmatrix}$):
$\text{Sens} = \frac{5}{15} = 33.3\%$, $\text{Spec} = \frac{10000}{10050} = 99.5\%$ $$\text{BA} = \frac{33.3\% + 99.5\%}{2} = \mathbf{66.4\%}$$ • Predict All $\mathbf{N}$: $\frac{0\% + 100\%}{2} = \color{#dc322f}{\mathbf{50\%}}$ (chance!)
$F_1$ Score (Harmonic Mean of $P, R$): $$F_1 = 2\,\frac{P \cdot R}{P + R}$$
• Our model ($\begin{smallmatrix}5 & 50\\ 10 & 10000\end{smallmatrix}$):
$P = \frac{5}{55} = 9.1\%$, $R = \frac{5}{15} = 33.3\%$ $$F_1 = \frac{2(0.091)(0.333)}{0.091 + 0.333} = \mathbf{14.3\%}$$ • Predict All $\mathbf{N}$: $R = 0 \implies \color{#dc322f}{\mathbf{F_1 = 0\%!}}$

Multiclass Confusion Matrix: Drug Repurposing

insilico

Which Metric is the right one?

Metrics

it depends

Cross Validation

5-fold cross validation

XV 5 fold

Cross validation results

XV bars

Grid search workflow

grid search workflow

Extra testing data

grid search cv

Grid Search: Combinatorial Explosion

5 × 5 Hyperparameter Grid (25 Models / Fold) h₁₁ h₁₂ h₁₃ h₁₄ h₁₅ h₂₁ h₂₂ h₂₃ h₂₄ h₂₅ Best (h₁₄, h₂₃)
  • $5$ values for $h_1 \times 5$ values for $h_2 = \mathbf{25\text{ models}}$ trained per fold!
  • Across $5$ folds: $5 \times 25 = \mathbf{125\text{ training runs}}$ (+ final refit on all training folds).
  • With $M$ hyperparameters of $G$ values each: $\mathcal{O}(K \cdot G^M)$ — exponential in $M$!

Nested Cross Validation

nested cv

Hyperparameter optimization

hyperopt hyperopt

Tools for hyperparameter optimization

Expected Value (profit)

Expected value

  • Let's denote an outcome $i$ as $o_i$
  • The probability of that outcome as $\prob{p}{o_i}$
  • And its value as $\prob{v}{o_i}$
  • The expected value is nothing but $$ EV = \sum_i^K \prob{p}{o_i}\cdot\prob{v}{o_i} $$

Example: targeted marketing

  • A consumer buys the product for $\$200$ and our product-related costs are $\$100$.
  • To target the consumer with the offer, we also incur a cost. Let’s say that we mail some flashy marketing materials, and the overall cost including postage is $\$1$, yielding a value (profit) of $\prob{v}{o_R} = \$99$ if the consumer responds (buys the product).
  • Now, what about $v_{NR}$, the value to us if the consumer does not respond? We still mailed the marketing materials, incurring a cost of $\$1$ or equivalently a benefit of $-\$1$.

Example: shall we target this specific consumer?

  • $\prob{p}{o_R} \cdot \$99 - [1 - \prob{p}{o_{R}}]\cdot \$1 \gt 0$
  • $\prob{p}{o_R} \cdot \$99 \gt [1 - \prob{p}{o_{R}}]\cdot \$1$
  • $\prob{p}{o_R} \gt 0.01$
  • Send marketing materials if probability of responding is $\gt 1\%$

First, convert confusion matrix to probabilities

1. Raw Counts ($N = 110$)
counts
Col $p$: $56+5=61$
Col $n$: $7+42=49$
2. Joint $\prob{p}{\text{Pred}, \text{Actual}}$
rates
Divide all cells by $110$:
$\prob{p}{p} = \frac{61}{110} = \mathbf{0.55},\; \prob{p}{n} = \frac{49}{110} = \mathbf{0.45}$
3. Conditional $\prob{p}{\text{Pred} \mid \text{Actual}}$
Actual p (0.55) n (0.45) Predicted Y N 0.92 56 / 61 0.14 7 / 49 0.08 5 / 61 0.86 42 / 49
Normalize each column by its sum:
$\prob{p}{Y\mid p}=0.92,\; \prob{p}{N\mid n}=0.86$

Second, estimate the cost benefit matrix

CB CB example

Expected Value Calculation

EV diagram
Actual (Priors) p (0.55) n (0.45) Predicted Y N 0.92 0.14 0.08 0.86 Cost benefit matrix reminder

Example: targeted marketing — What's the profit?

\begin{align} EV = &\, \prob{p}{Y, p} \prob{b}{Y, p} + \prob{p}{N, p} \prob{b}{N, p} + \prob{p}{N, n} \prob{b}{N, n} + \prob{p}{Y, n} \prob{b}{Y, n} \\ = & \fragment{0}{\, \prob{p}{Y| p}\prob{p}{p} \prob{b}{Y, p} + \prob{p}{N|p} \prob{p}{p} \prob{b}{N, p}} \\ & \fragment{0}{+ \prob{p}{N|n} \prob{p}{n} \prob{b}{N, n} + \prob{p}{Y|n} \prob{p}{n} \prob{b}{Y, n}}\\ = &\, \fragment{1}{\prob{p}{p} \left[ \prob{p}{Y| p} \prob{b}{Y, p} + \prob{p}{N|p} \prob{b}{N, p} \right]} \\ & \fragment{1}{+ \prob{p}{n} \left[ \prob{p}{N|n} \prob{b}{N, n} + \prob{p}{Y|n} \prob{b}{Y, n} \right]}\\ =&\, \fragment{2}{0.55 \left[ 0.92\cdot \prob{b}{Y, p} + 0.08\cdot \prob{b}{N, p} \right]} \\ & \fragment{2}{+ 0.45 \left[ 0.86\cdot \prob{b}{N, n} + 0.14\cdot \prob{b}{Y, n} \right]}\\ =&\, \fragment{3}{0.55 \left[ 0.92\cdot99 + 0.08\cdot 0 \right] + 0.45 \left[ 0.86\cdot 0 + 0.14\cdot (-1) \right]}\\ =&\, \fragment{4}{\$50.04} \end{align}

What did we learn?

Decisions have costs

Visualizing model performance

Remember that Bayesian decision boundary?

decision boundary

Let's move the boundary around until we are happy

Cutoffs

A classifier and confusion matrix

With a ranking classifier, a classifier plus a threshold produces a single confusion matrix.
sorted data

Profit Curve: Example (Small Margin)

small profit margin

Profit Curves Across Classifiers

profit curves

Receiver Operating Characteristics (ROC)

ww2

From Profit Curves to ROC

  • Profit curves work well only when class priors and costs/benefits are known and stable.
  • In practice, priors fluctuate (e.g., fraud rates vary month-to-month) and campaign budgets/costs change.
  • Receiver Operating Characteristic (ROC) decouples performance from priors and costs by plotting the two column quotients!

ROC Axes: Hit Rate (TPR) vs. False Alarm Rate (FPR)

Sensitivity / Recall (TPR) Top-Left (TP) ÷ True Positive Column (p) Numerator pnPNTPFPFNTN = TP / (TP + FN) Divided by pnPNTPFPFNTN False Positive Rate (FPR / False Alarm) Top-Right (FP) ÷ True Negative Column (n) Numerator pnPNTPFPFNTN = FP / (FP + TN) Divided by pnPNTPFPFNTN

ROC Space

ROC

ROC: Each Point Is a Threshold

ROC curve

ROC Construction: Step by Step

ROC construction

Area Under the ROC Curve (AUC)

AUC

What Does AUC Mean Probabilistically?

Equivalent to the Mann-Whitney-Wilcoxon ranking statistic (and Gini coefficient):
$$\text{AUC} = \PP\Big( s(\vec{x}_{+}) > s(\vec{x}_{-}) \Big)$$ The probability that a randomly chosen positive sample $\vec{x}_{+}$ is ranked (scored) higher than a randomly chosen negative sample $\vec{x}_{-}$!

Threshold, ROC Space & Expected Profit Explorer

On Model Calibration

What is Model Calibration?

Model calibration is the problem of predicting probability estimates representative of the true correctness likelihood

Why do we need it?

We want the probability associated with the predicted class label to reflect its ground truth correctness likelihood.
If that is the case, we know when we can trust the model, and when to route the decision to a human!

Modern Best-Performing Models Are Lying

LeNet vs ResNet
  • 5-layer LeNet (1998) is well-calibrated
  • 110-layer ResNet (2016) achieves much higher accuracy, yet is poorly calibrated (overconfident)
  • Why does this happen, and how do we fix it?

Formal definitions

  • Inputs $X \in {\cal X}$ and labels $Y \in {\cal Y} = \{1, \dots, K\}$ follow ground truth joint distribution $\pi(X,Y) = \pi(Y|X)\pi(X)$.
  • A neural network $h(X) = (\hat{Y}, \hat{P})$ outputs a class prediction $\hat{Y}$ and a confidence score $\hat{P}$.
  • We want the confidence estimate $\hat{P}$ to be calibrated, which intuitively means that $\hat{P}$ represents a true probability.
  • Perfect calibration:
$$ \PP(\hat{Y} = Y \mid \hat{P} = p) = p, \quad \forall p \in [0, 1] $$

Reliability Diagrams

LeNet vs ResNet
  • Reliability Diagrams visualize model calibration (DeGroot & Fienberg, 1983)
  • Plot expected sample accuracy as a function of confidence
  • Perfect calibration ($\PP(\hat{Y} = Y | \hat{P} = p) = p$) lies on the identity diagonal
  • Any deviation from the diagonal is miscalibration

Calibration Across Classical Classifiers

sklearn calibration curves

Reliability Diagrams: Binning

  • Group predictions into $M$ interval bins (each of size $1/M$) and calculate the accuracy of each bin.
  • Let $B_m$ be the set of indices of samples whose prediction confidence falls into the interval $I_m = (\frac{m-1}{M}, \frac{m}{M}]$.
  • The accuracy of $B_m$ is: $$ \mbox{acc}(B_m) = \frac{1}{|B_m|} \sum_{i \in B_m} \mathbf{1}(\hat{y}_i = y_i) $$
  • The average confidence within bin $B_m$ is: $$ \mbox{conf}(B_m) = \frac{1}{|B_m|} \sum_{i \in B_m} \hat{p}_i $$

Expected Calibration Error (ECE)

  • We use empirical approximations directly: $$ \EE_{\hat{P}}\left[ \left| \PP(\hat{Y} = Y | \hat{P} = p) - p \right| \right] $$
  • Expected Calibration Error (ECE) — weighted average of the red gap bars across all $M$ bins: $$ \mbox{ECE} = \sum_{m=1}^M \frac{|B_m|}{n} \left| \mbox{acc}(B_m) - \mbox{conf}(B_m) \right| $$
  • Maximum Calibration Error (MCE) — worst-case bin gap for high-risk applications: $$ \mbox{MCE} = \max_{m \in \{1,\dots, M\}} \left| \mbox{acc}(B_m) - \mbox{conf}(B_m) \right| $$

Negative Log-Likelihood (NLL)

  • A standard measure of a probabilistic model's quality (also known as cross-entropy loss in deep learning).
  • Given a probabilistic model $\hat{\pi}(Y|X)$ and $n$ samples: $$ {\cal L} = - \sum_{i=1}^n \log\left(\hat{\pi}(y_i|x_i)\right) $$
  • NLL is a proper scoring rule: in expectation, it is minimized if and only if $\hat{\pi}(Y|X)$ recovers the ground truth conditional distribution $\pi(Y|X)$.

What Affects Calibration?

  • Increasing depth and width reduces classification error, but hurts calibration.
  • Models trained with Batch Normalization or less weight decay are more miscalibrated.
Architecture effects

Accuracy vs. NLL During Training

The network overfits NLL (becoming overconfident) long after 0/1 classification error plateaus!

Error and NLL

Temperature Scaling

  • The neural network computes a vector of non-probabilistic logits $\vec{z}_i$ for each input $\vec{x}_i$, before the softmax layer $\sigma_{\text{SM}}$: $$ \hat{p}_i = \max_k \sigma_{\text{SM}}(\vec{z}_i)^{(k)} = \max_k \frac{\exp(z_i^{(k)})}{\sum_{j=1}^K \exp(z_i^{(j)})} $$
  • Temperature Scaling divides the logits by a single scalar parameter $T > 0$ before the softmax: $$ \hat{q}_i = \max_k \sigma_{\text{SM}}\left(\frac{\vec{z}_i}{T}\right)^{(k)} $$

Properties of Temperature Scaling

  • $T = 1$: recovers the original uncalibrated probabilities $\hat{p}_i$.
  • As $T > 1$ increases: softens the softmax distribution (raises output entropy) and cures overconfidence.
  • As $T \to \infty$: $\hat{q}_i \to 1/K$ (uniform maximum uncertainty).
  • As $T \to 0$: collapses to a point mass ($\hat{q}_i \to 1$).
  • $T$ is optimized with respect to NLL on the validation set (with network weights frozen).
  • Because $z_i^{(k)} / T$ is strictly monotonic for $T > 0$, $\argmax_k$ is unchanged — Top-1 Accuracy is 100% preserved!

Results: Expected Calibration Error (ECE)

ECE table

Reliability Diagram, ECE & Temperature Scaling

Take Home Points

  • Bias–Variance & Double Descent: Classical test risk balances $\text{Bias}^2$ and $\text{Variance}$, peaking at the interpolation threshold ($p = n$) before descending a second time as minimum-norm interpolants shrink $\|\hat{\vth}\|_2$ for $p \gg n$.
  • Why Raw Accuracy Fails: Under class skew ($95\%/5\%$), predicting the majority class everywhere achieves $95\%$ accuracy while failing on the rare class; manually rebalancing to $50\%/50\%$ reverses the winner in the wild.
  • Confusion Matrix Quotients: Sensitivity ($\text{TP}/\mathbf{P}$) & Specificity ($\text{TN}/\mathbf{N}$) normalize by true columns ($\to$ Balanced Accuracy); Precision ($\text{TP}/\text{Pred }\mathbf{P}$) & Recall ($\text{TP}/\mathbf{P}$) combine into $F_1$.
  • Expected Profit & ROC / AUC: When priors & costs are known, optimize $EV(\tau)$; when unstable, plot $\text{TPR}$ vs. $\text{FPR}$ (ROC), where $\text{AUC} = \PP(s(\vec{x}_{+}) > s(\vec{x}_{-}))$.
  • Model Calibration & Temperature Scaling: Deep networks overfit NLL and become overconfident; dividing logits by a single validation-tuned scalar $T > 0$ aligns $\hat{P}$ with true accuracy while preserving Top-1 Accuracy.