Uncertainty Calibration Error: A New Metric for Multi-Class Classification

1 INTRODUCTION . Advances in deep learning have led to superior accuracy in classification tasks , making deep learning classifiers an attractive choice for safety-critical applications like autonomous driving ( Chen et al. , 2015 ) or computer-aided diagnosis ( Esteva et al. , 2017 ) . However , the high accuracy of recent deep learning models alone is not sufficient for such applications . In cases where serious decisions are made upon model ’ s predictions , it is essential to also consider the uncertainty of these predictions . We need to know if a prediction is likely to be incorrect or if invalid input data is presented to a deep model , e.g . data that is far away from the training domain or obtained from a defective sensor . The consequences of a false decision based on an uncertain prediction can be fatal . A natural expectation is that the certainty of a prediction should be directly correlated with the quality of the prediction . In other words , predictions with high certainty are more likely to be accurate than uncertain predictions , which are more likely to be incorrect . A common misconception is the assumption that the estimated softmax likelihood can be directly used as a confidence measure for the predicted class . This expectation is dangerous in the context of critical decision-making . The estimated likelihood of models trained by minimizing the negative log-likelihood ( i.e . cross entropy ) is highly overconfident ; that is , the estimated likelihood is considerably higher than the observed frequency of accurate predictions with that likelihood ( Guo et al. , 2017 ) . 2 UNCERTAINTY ESTIMATION . In this work , we focus on uncertainty from approximately Bayesian methods . We assume a general multi-class classification task with C classes . Let input x ∈ X be a random variable with corresponding label y ∈ Y = { 1 , . . . , C } . Let fw ( x ) be the output ( logits ) of a neural network with weight matrices w , and with model likelihood p ( y=c |fw ( x ) ) for class c , which is sampled from a probability vector p = σSM ( fw ( x ) ) , obtained by passing the model output through the softmax function σSM ( · ) . From a frequentist perspective , the softmax likelihood is often interpreted as confidence of prediction . Throughout this paper , we follow this definition . The frequentist approach assumes a single best point estimate of the parameters ( or weights ) of a neural network . In frequentist inference , the weights of a deep model are obtained by maximum likelihood estimation ( Bishop , 2006 ) , and the normalized output likelihood for an unseen test input does not consider uncertainty in the weights ( Kendall & Gal , 2017 ) . Weight uncertainty ( also referred to as model or epistemic uncertainty ) is a considerable source of predictive uncertainty for models trained on data sets of limited size ( Bishop , 2006 ; Kendall & Gal , 2017 ) . Bayesian neural networks and recent advances in their approximation provide valuable mathematical tools for quantification of model uncertainty ( Gal & Ghahramani , 2016 ; Kingma & Welling , 2014 ) . Instead of assuming the existence of a single best parameter set , we place distributions over the parameters and want to consider all possible parameter configurations , weighted by their posterior . More specifically , given a training data set D and an unseen test sample x with class label y , we are interested in evaluating the predictive distribution p ( y|x , D ) = ∫ p ( y|x , w ) p ( w|D ) dw . This integral requires to evaluate the posterior p ( w|D ) , which involves the intractable marginal likelihood . A possible solution to this is to approximate the posterior with a more simple , tractable distribution q ( w ) by optimization . In this work , we incorporate the following approximately Bayesian methods which we use in our experiments to obtain weight uncertainty : Monte Carlo ( MC ) dropout ( Gal & Ghahramani , 2016 ) , Gaussian dropout ( Wang & Manning , 2013 ; Kingma et al. , 2015 ) , Bayes by Backprop ( Blundell et al. , 2015 ) , SWA-Gaussian ( Maddox et al. , 2019 ) , and ( although not Bayesian ) deep ensembles ( Lakshminarayanan et al. , 2017 ) . A short review of each of the methods can be found in Appendix A.2 . 3 RELATED CALIBRATION METRICS . Expected Calibration Error The expected calibration error ( ECE ) is one of the most popular calibration error metrics and estimates model calibration by binning the predicted confidences p̂ = maxc p ( y = c |x ) into M bins from equidistant intervals and comparing them to average accuracies per bin ( Naeini et al. , 2015 ; Guo et al. , 2017 ) : ECE = M∑ m=1 |Bm| n ∣∣acc ( Bm ) − conf ( Bm ) ∣∣ , ( 1 ) with number of test samples n and acc ( B ) and conf ( B ) denoting the accuracy and confidence of bin B , respectively . Several recent works have described severe pathologies of the ECE metric ( Ashukha et al. , 2020 ; Nixon et al. , 2019 ; Kumar et al. , 2019 ) . Most notably , the ECE metric is minimized by a model constantly predicting the marginal distribution of the majority class which makes it impossible to directly optimize it ( Kumar et al. , 2018 ) . Additionally , the ECE only considers the maximum class probability and ignores the remaining entries of the probability vector p ( x ) . Adaptive Calibration Error Nixon et al . ( 2019 ) proposed the adaptive calibration error ( ACE ) to address the issue of fixed bin widths of ECE-like metrics . For models with high accuracy or overconfidence , most of the predictions fall into the rightmost bins , whereas only very few predictions fall into the rest of the bins . ACE spaces the bins such that an equal number of predictions contribute to each bin . The final ACE is computed by averaging over per-class ACE values to address the issue raised by Kull et al . ( 2019 ) . However , this makes the metric more sensitive to the manually selected number of bins M as the number of bins effectively becomes C ·M , with number of classes C. Using fixed bin widths , the numbers of samples in the sparsely populated bins is further reduced , which increases the variance of each measurement per bin . Using adaptive bins , this results in the lower confidence bins spanning a wide range of values , which increases the bias of the bin ’ s measurement . Negative Log-Likelihood Deep models for classification are usually trained by minimizing the average negative log-likelihood ( NLL ) : NLL = 1 N N∑ i=1 − log p ( y = yi |xi ) . ( 2 ) The NLL is also commonly used as a metric for measuring the calibration of uncertainty . However , the NLL is minimized by increasing the confidence maxc p ( y = c |x ) , which favors over-confident models and models with higher accuracy ( Ashukha et al. , 2020 ) . This metric is therefore unable to compare the calibration of models with different accuracies and training a model by minimizing NLL does not necessarily lead to good calibration . Brier Score The average Brier score is another popular metric for assessing the quality of predictive uncertainty and is defined as ( Brier , 1950 ; Lakshminarayanan et al. , 2017 ) BS = 1 N N∑ i=1 C∑ c=1 ( 1 ( yi = c ) − p ( y = c |xi ) ) 2 . ( 3 ) Similarly to the NLL , the Brier score favors high probabilities for correct predictions and low probabilities for incorrect predictions . Thus , models with higher accuracy tend to show a better Brier score , which makes the metric unsuitable for comparing the quality of uncertainty for models with different accuracies . Maximum Mean Calibration Error Common recalibration methods are applied post-hoc , e.g . temperature scaling on a separate calibration set . Kumar et al . ( 2018 ) proposed the maximum mean calibration error ( MMCE ) , a trainable calibration surrogate for the calibration error . It is defined as MMCE2 ( D ) = ∑ i , j∈D ( 1 ( ŷi = yi ) − p̂i ) ( 1 ( ŷj = yj ) − p̂j ) k ( p̂i , p̂j ) m2 ( 4 ) over batch D ⊂ D with batch size m , matrix-valued universal kernel k and ŷ = argmaxc p ( y = c |x ) . Trainable calibration metrics are used in joint optimization with the negative log-likelihood argmin w ∑ D NLL ( D , w ) + λMMCE ( D , w ) . ( 5 ) Kumar et al . ( 2018 ) claim to have addressed the issue that the ECE is unsuitable for direct optimization due to its high discontinuity in w. However , MMCE is also minimized by a model constantly predicting the marginal distribution of the classes . This leads to subpar logit temperature when training with MMCE and temperature scaling can further reduce miscalibration ( Kumar et al. , 2018 ) . 4 UNCERTAINTY CALIBRATION ERROR . To give an insight into our general approach to measuring the calibration of uncertainty , we will first revisit the definition of perfect calibration of confidence ( Guo et al. , 2017 ) and show how this concept can be extended to calibration of our definition uncertainty . Let ŷ = argmaxp be the most likely class prediction of input x with confidence p̂ = maxp and true label y . Then , following Guo et al . ( 2017 ) , perfect calibration of confidence is defined as P [ ŷ = y | p̂ = α ] = α , ∀α ∈ [ 0 , 1 ] . ( 6 ) That is , the probability of a correct prediction ŷ = y given the prediction confidence p̂ should exactly correspond to the prediction confidence . Instead of using only the probability of the predicted class , we use the entropy of p to express prediction uncertainty : H ( p ) = − C∑ c=1 p ( c ) log p ( c ) . ( 7 ) Let q ( k ) : = ( P [ y = 1| argmaxp ( x ) = k ] , . . . , P [ y = C| argmaxp ( x ) = k ] ) ( 8 ) be a probability vector of true marginal class probabilities for all inputs x predicted with class k. Consider the following example : Three i.i.d . inputs x1:3 in a binary classification task with ground truth labels { 1 , 1 , 2 } have all been predicted with argmaxp ( x1:3 ) = 1 . Then , q ( 1 ) = ( 2 3 , 1 3 ) . With this , we define a model to be perfectly calibrated if H ( q ( k ) ) = H ( p | argmaxp = k ) ∀ k ∈ { 1 , . . . , C } . ( 9 ) From this , we derive an error metric for calibration of uncertainty : Ep [ |H ( q ) −H ( p ) | ] . ( 10 ) However , this metric and the use of the entropy as measure of uncertainty lacks interpretability , as the entropy scales with the number of classes C. This does not allow to compare the uncertainty or the calibration of models trained on different data sets . Therefore , we propose to use the normalized entropy to scale the values to a range between 0 and 1 : H̃ ( p ) : = − 1 logC C∑ c=1 p ( c ) log p ( c ) , H̃ ∈ [ 0 , 1 ] . ( 11 ) We further increase interpretability and argue , that the normalized entropy should correlate with the model error . From Eq . ( 6 ) and Eq . ( 11 ) , we define perfect calibration of uncertainty as P [ ŷ 6= y | H̃ ( p ) = α ] = α , ∀α ∈ [ 0 , 1 ] . ( 12 ) That is , in a batch of inputs that are all predicted with uncertainty of e. g. 0.2 , a top-1 error of 20 % is expected . The confidence is interpreted as the probability of belonging to a particular class , which should naturally correlate with the model error of that class . This characteristic does not generally apply to entropy , and thus the question arises why entropy should correspond with the model error . Proposition 1 . The normalized entropy ( uncertainty ) H̃ ( p ) approaches the top-1 error in the limit of number of classes C if the model p is well-calibrated . Proof . lim C→∞ H̃ ( p ) = ( 1− p̂ ) ( 13 ) The top-1 error equals ( 1 − p̂ ) if the model is perfectly calibrated in the sense of Eq . ( 6 ) . For a detailed proof , see Appendix A.1 . Thus , the normalized entropy gives us an intuitive and interpretable measure of uncertainty . If a model is perfectly calibrated , H̃ corresponds to the top-1 error . We propose the following notion to quantify miscalibration of uncertainty : EH̃ [ ∣∣P [ ŷ 6= y | H̃ ( p ) = α ] − α∣∣ ] , ∀α ∈ [ 0 , 1 ] . ( 14 ) We refer to this as Expected Uncertainty Calibration Error ( UCE ) and approximate with UCE : = M∑ m=1 |Bm| n ∣∣err ( Bm ) − uncert ( Bm ) ∣∣ , ( 15 ) using the same binning scheme as in ECE estimation . The error per bin is defined as err ( Bm ) : = 1 |Bm| ∑ i∈Bm 1 ( ŷi 6= y ) , ( 16 ) where 1 ( ŷi 6= y ) = 1 and 1 ( ŷi = y ) = 0 . Uncertainty per bin is defined as uncert ( Bm ) : = 1 |Bm| ∑ i∈Bm H̃ ( pi ) . ( 17 ) Properties of UCE The proposed UCE metric solves several problems of other metrics . First , the UCE is not zero for a model constantly predicting the marginal class distribution . Estimators of metrics with this pathology ( e.g . ECE , MMCE ) suffer from varying bias and therefore do not allow comparing miscalibration of different models ( Ashukha et al. , 2020 ; Vaicenavicius et al. , 2019 ) . In contrast to ACE , UCE is not highly sensitive to the numbers of bins and provides a consistent ranking of different models for the same classification task ( see Fig . 1 ) . Additionally , UCE can be used as a trainable regularizer in similar manner to MMCE . During training , we compute the UCE over mini-batches D ⊂ D and add it to the NLL training objective argmin w ∑ D NLL ( D , w ) + λUCE ( D , w ) , ( 18 ) weighted by a factor λ. UCE is zero for an optimal model and thus does not penalize high confident predictions for models with high accuracy , which is a major disadvantage of plain entropy regularization ( Pereyra et al. , 2017 ) . Predictions with low uncertainty , but high top-1 error are penalized whereas predictions with high accuracy are encouraged to have low uncertainty .

Summary: This paper proposes a new calibration error measurement named UCE (Uncertainty Calibration Error) for deep classification models. It consists in doing a calibration in order to achieve "perfect calibration" (i.e., the uncertainty provided is equivalent to the classification error at all levels in [0, 1]), relying on normalized entropy for multiclass classification. This UCE is well justified for classification problems with several classes to process, where the entropy is demonstrated to be asymptotically equivalent to the classification (top-1) error. A point with this UCE metric is that is has some interpretability properties in terms of its value, and is said to be robust to the number of bins used.