Taking a Step Back with KCal: Multi-Class Kernel-Based Calibration for Deep Neural Networks

Zhen Lin, Shubhendu Trivedi, Jimeng Sun

Abstract

Deep neural network (DNN) classifiers are often overconfident, producing miscalibrated class probabilities. In high-risk applications like healthcare, practitioners require fully calibrated probability predictions for decision-making. That is, conditioned on the prediction vector, every class’ probability should be close to the predicted value. Most existing calibration methods either lack theoretical guarantees for producing calibrated outputs, reduce classification accuracy in the process, or only calibrate the predicted class. This paper proposes a new Kernel-based calibration method called KCal. Unlike existing calibration procedures, KCal does not operate directly on the logits or softmax outputs of the DNN. Instead, KCal learns a metric space on the penultimate-layer latent embedding and generates predictions using kernel density estimates on a calibration set. We first analyze KCal theoretically, showing that it enjoys a provable full calibration guarantee. Then, through extensive experiments across a variety of datasets, we show that KCal consistently outperforms baselines as measured by the calibration error and by proper scoring rules like the Brier Score.

Introduction

Modern Deep Neural Networks (DNNs) are notoriously overconfident. While they might be highly accurate, the "probabilities" they output (the softmax scores) rarely reflect the true likelihood of being correct—a phenomenon known as miscalibration. Most existing solutions focus on confidence calibration, which only ensures the probability of the predicted class is accurate. However, in high-stakes fields like medicine, practitioners need full calibration. If a model suggests a patient has a 10% chance of a rare but deadly seizure, that 10% needs to be a reliable statistical estimate, not just a byproduct of a model focused on its top guess.

Reliability diagrams for the IIIC dataset showing that while Temperature Scaling (TS) can calibrate overall confidence, it fails to calibrate specific critical classes like Seizures.

Existing full-calibration methods often suffer from a "calibration-accuracy trade-off," where fixing the probabilities degrades the model's actual performance. KCal addresses this by "taking a step back" from the final output layer, operating instead on the latent embeddings.

Methodology: The KCal Framework

KCal (Kernel-based Calibration) replaces the final linear classification layer during the calibration phase. The process involves four key steps:

  1. Latent Embedding: KCal utilizes the penultimate layer's latent embeddings ($f(X)$).
  2. Metric Learning: A shallow MLP ($\Pi$) projects these embeddings into a low-dimensional metric space (typically 32 or 128 dimensions).
  3. KDE Classification: Predictions for new data points are generated via Kernel Density Estimation (KDE) using a holdout calibration set. By examining "neighbors" in the learned metric space, KCal determines the probability distribution across all $K$ classes.
  4. Bandwidth Tuning: The kernel's bandwidth is automatically tuned on the calibration set to minimize log-loss.

Crucially, KCal provides a provable full calibration guarantee with finite sample error bounds, a significant theoretical advancement over existing methods.

Experimental Evaluation

The researchers evaluated KCal against a wide array of benchmarks, including computer vision (CIFAR-10/100, SVHN, ImageNet) and healthcare monitoring (IIIC seizure detection, ISRUC sleep staging, PN2017 ECG classification).

Accuracy comparison across various datasets and calibration methods. KCal consistently maintains or improves classification accuracy compared to uncalibrated models and other baselines.

Key Results

  • Superior Calibration: KCal consistently achieved the lowest Class-wise Expected Calibration Error (CECE) and Brier Score across almost all tested datasets.
  • Accuracy Gains: Unlike "binning" methods that often lose nuance, KCal's continuous kernel approach frequently improves accuracy. For instance, on the PN2017 dataset, KCal improved accuracy by nearly 6% over the uncalibrated baseline.
  • Rare Class Reliability: KCal excels at calibrating rare classes. In the IIIC seizure dataset, standard methods failed on the specific "Seizure" class, while KCal produced a reliable reliability diagram.
  • Robustness: KCal demonstrated superior performance under distributional shift, a common failure point for scaling-based methods like Temperature Scaling.

Discussion and Conclusion

KCal represents a shift in calibration philosophy. By moving logic to the latent space, it preserves class relationship information often lost in the final softmax layer. While it introduces a small memory overhead (storing projected embeddings) and slightly higher inference latency due to KDE, these costs are negligible compared to the gains in reliability and accuracy. Future work may explore "Kernel Herding" to further reduce the calibration set size. In summary, KCal offers a robust, theoretically grounded solution for full calibration in high-stakes deep learning applications.

Summary updated

BibTeX
@misc{lin2022taking,
  author = {Zhen Lin and Shubhendu Trivedi and Jimeng Sun},
  title = {{Taking a Step Back with KCal: Multi-Class Kernel-Based Calibration for Deep Neural Networks}},
  year = {2022},
  eprint = {2202.07679},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.07679},
}
Figure