Classifier calibration: a survey on how to assess and improve predicted class probabilities

This paper provides both an introduction to and a detailed overview of the principles and practice of classifier calibration. A well-calibrated classifier correctly quantifies the level of uncertainty or confidence associated with its instance-wise predictions. This is essential for critical applications, optimal decision making, cost-sensitive classification, and for some types of context change. Calibration research has a rich history which predates the birth of machine learning as an academic field by decades. However, a recent increase in the interest on calibration has led to new methods and the extension from binary to the multiclass setting. The space of options and issues to consider is large, and navigating it requires the right set of concepts and tools. We provide both introductory material and up-to-date technical details of the main concepts and methods, including proper scoring rules and other evaluation metrics, visualisation approaches, a comprehensive account of post-hoc calibration methods for binary and multiclass classification, and several advanced topics.


Introduction and motivation
A K-class probabilistic classifier is well-calibrated if among test instances receiving a predicted K-dimensional probability vector s, the class distribution is (approximately) distributed as s. This property is of fundamental importance when using a classifier for cost-sensitive classification, for human decision making, or within an autonomous system. It means that the classifier correctly quantifies the level of uncertainty or confidence associated with its predictions. In a binary setting, scores given by a sufficiently calibrated classifier can be simply thresholded to minimise expected misclassification cost. Thresholds can also be derived to optimally adapt to a change in class prior, or to a combination of both. In contrast, for a poorly calibrated classifier the optimal thresholds cannot be obtained without optimisation.
Many machine learning algorithms are known to produce over-confident models, unless dedicated procedures are applied during training. The goal of (post-hoc) calibration methods is to use hold-out validation data to learn a calibration map for a previously trained model that transforms the model's predictions to be better calibrated. Many calibration methods for binary classifiers have been introduced, including logistic calibration (also known as 'Platt scaling'), various binning methods including isotonic calibration (also known as the ROC convex hull method), as well as more recent methods including beta calibration and Bayesian methods.
When we have more than two classes, calibration is generally more involved, as is often the case with multiclass classification. Multiclass calibration has mostly been approached by decomposing the problem into K one-vs-rest binary calibration tasks, one for each class. The predictions of these K calibration models form unnormalised probability vectors, which, after normalisation, may not be calibrated in a multiclass sense. Native multiclass calibration methods were introduced recently focusing on neural networks. These methods constitute various multiclass extensions of Platt scaling, adding a calibration layer between the logits of the neural network and the softmax layer.
The literature on post-hoc classifier calibration in machine learning is now sufficiently rich that it is no longer straightforward to obtain or maintain a good overview of the area, which was the main motivation for writing this survey. It grew out of a tutorial we presented at the 2020 European Conference on Machine Learning and Principles and Practice of Knowledge Discovery in Databases (see https:// classifier-calibration.github.io). Our aim then and now is to provide both introductory material and up-to-date technical details of the main concepts and methods. Our focus is on the classical setup where the classifier is deployed in the same setting where it was calibrated, except for potential changes in class prior or misclassification costs. We do not cover methods to achieve robustness under conditions of other distributional shifts or out-of-distribution inputs (Ovadia et al., 2019). We try to do justice to historical developments and pay attention to important topics that are not as widely known as they deserve to be, such as proper scoring rules.
We also try to identify and clarify possible sources for confusion. The multiclass setting in particular introduces numerous subtleties that have not always been recognised or correctly dealt with in previous work. For example, some authors use the weaker notion of confidence calibration, which requires only that the classifier's predicted probability for what it considers the most likely class is calibrated. While this is perfectly valid in its own right, it isn't always appreciated by subsequent authors that this is a much weaker notion of calibration than the one defined informally in the first sentence of this survey. One can also observe variations in the evaluation metric used and in the way calibrated probabilities are visualised. Our main aim in this survey is hence to provide a unified perspective on the different methods and metrics for binary and multiclass calibration, giving each variation its proper place.
For the purpose of this survey we have developed a Python library which includes most of the functionalities presented in the following sections. PyCalib 1 implements several calibration metrics (eg. confidence and classwise ECE, and their MCE counterparts), common calibration methods (eg. Isotonic Calibration, Platt's Scaling, Binning calibration), a method to combine arbitrary classifiers and calibrators into a unified training and deployment pipeline, a one-vs-the-rest implementation to adapt any binary calibration method to the multiclass setting, and multiple visualisation tools to inspect visually the calibration quality as well as tools to get better insights about the learned calibration maps. As an illustration of the library's capabilities, most of the figures and results reported in this paper have been generated using PyCalib.
The survey is structured as follows. The next section will cover important notions and intuitions related to calibration. It aims to be at a more introductory level, leaving technical detail for later sections. Section 3 discusses proper scoring rules, an important general framework for evaluation of probability estimates. In Section 4 we present systematic overview of visualisation approaches and evaluation metrics for classifier calibration. Section 5 is devoted to a comprehensive account of post-hoc calibration methods for both the binary and multiclass scenarios. Section 6 covers hypothesis tests for calibration, and Section 7 concludes with a summary and outlook.

A brief introduction to classifier calibration
The origins of classifier calibration can be traced back to weather forecasting and meteorology. Here is what the UK Met Office website used to say about what their forecast probabilities mean: "[S]uppose the Met Office says that the probability of rain tomorrow in your region is 80%. They aren't saying that it will rain in 80% of the land area of your region, and not rain in the  Hallenbeck (1920). other 20%. Nor are they saying it will rain for 80% of the time. What they are saying is there is an 80% chance of rain occurring at any one place in the region, such as in your garden. [...] [A] forecast of 80% chance of rain in your region should broadly mean that, on about 80% of days when the weather conditions are like tomorrow's, you will experience rain where you are. [...] If it doesn't rain in your garden tomorrow, then the 80% forecast wasn't wrong, because it didn't say rain was certain. But if you look at a long run of days, on which the Met Office said the probability of rain was 80%, you'd expect it to have rained on about 80% of them. " (https://web.archive.org/web/20210928235732/https://www.metoffice.gov .uk/about-us/what/accuracy-and-trust/probability) Note the phrase "a long run of days": determining the degree to which a forecaster is well-calibrated cannot be done on a per-forecast basis, but rather requires looking at a sufficiently large and diverse set of forecasts.    Table 1 in five (left figure) and two (right figure) equal-width bins. Table 1, reproduced from Hallenbeck (1920), groups 123 weather forecasts in 10 equal-width bins, and compares each bin with the actual empirical percentage of rain events. Figure 1 shows two possibilities of displaying this information graphically, comparing the predicted probabilities on the x-axis to empirical probabilities on the y-axis. A variety of such graphical representations can be found in the literature; they are generally known as reliability diagrams, 'reliability' being one of many terms used to denote goodness of calibration (Murphy & Winkler, 1977). We can see that most of the forecasts are slight under-estimates: for example, of the 15 forecasts in the 40-49% bin, 8/15 = 53% were actual rain events. In the left graph this is shown by the vertical red line, which indicates how much the top of the blue bar extends above the diagonal (meaning that the actual proportion of rain events was higher than estimated). On the right graph this can be seen directly from how much the respective point is higher than the diagonal. Similarly, we see that two of the bins (20-29% and 30-39%) are very slight over-estimates: on the left graph the top of the blue bar is below the diagonal, which means that the actual proportion of rain events was lower than estimated.
The choice of ten equal-width bins is somewhat arbitrary, and it is informative to consider different choices. Merging pairs of adjacent bins results in five equal-width bins, as depicted in Figure 2 (left). We see that all but the right-most bin averages are now slightly off-centre (we assumed that within each original bin all forecast probabilities are the same and equal to the bin centre: e.g., 25% in the 20-29% bin). Again, the pattern is that the higher forecast probabilities are about 10% too low. Figure 2 (right) shows what we get with only two bins. We have lost a bit too much information here, so bins shouldn't be taken too wide. On the other hand they shouldn't be taken too narrow either, in order to be able to measure the true proportion of rain events with sufficient resolution.
Taking the forecast event as a binary variable means that the calibration concept is directly applicable to binary classification. Here is an example from the typical machine learning task of learning a classifier for distinguishing 'junk' or 'spam' emails from regular ones: A prediction '70% chance of spam' should be spam 70% of the time.
And a generalisation to categorical variables with more than two values is equally straightforward, as this example from Fisher's famous Iris dataset shows: A prediction '70% chance of setosa, 10% chance of versicolor and 20% chance of virginica' should be setosa/versicolor/virginica 70/10/20% of the time.
So, to sum up: A predicted probability (vector) should match empirical (observed) probabilities. In the language of predictive machine learning, given an instance space X, a binary target space Y = {+, −}, and a binary probabilistic classifier f : X → [0, 1], the binary classifier is calibrated if ∀s ∈ [0, 1]:

Why calibration matters
What are the benefits of using well-defined calibrated scales in general, and wellcalibrated probabilities in particular? One obvious benefit of calibrated scales is that we can easily combine measurements that are expressed on the same scale without comparing apples and oranges. Another is that we can use standardised decision rules, e.g., defining a fever as a body temperature exceeding 100 degrees Fahrenheit. These benefits directly carry over to the class probability scenario, justifying decision rules such as predicting the class whose estimated probability exceeds 0.5 in binary classification, or the class with the highest predicted probability for multiclass classification. Importantly, there is a further benefit to using calibrated probabilities as it means we can adjust these decision rules in a straightforward way to account for different class priors or misclassification costs, as we will briefly discuss presently.
Let c = C(+|−) C(+|−)+C(−|+) be the cost of a false positive in proportion to the combined cost of one false positive and one false negative. With these cost parameters the Bayes-optimal decision rule is to set the decision threshold to c. For instance, if false positives are 4 times as costly as false negatives then we set the decision threshold to 4/(4 + 1) = 0.8 in order to only make positive predictions if we are sufficiently certain. Similar reasoning applies to changes in class priors: • if we trained on balanced classes but want to deploy with 4 times as many positives compared to negatives, we lower the decision threshold to 0.2; • more generally, if we trained for class ratio r and deploy for class ratio r we set the decision threshold to r/(r + r ).
Cost and class prior changes can be combined in the obvious way; see P. Flach (2014) for details. In summary, an important reason to be interested in calibrating our classifiers is that default decision rules such as predicting the class with the highest predicted probability are fully justified from a decision-theoretic point of view, and can easily be adapted to changes in class and cost distributions. In contrast, poorly calibrated classifiers such as naive Bayes will often perform sub-optimally with default decision rules. It is possible to learn a better decision rule for a given cost and class skew using,  x-axis shows predicted probabilities and y-axis shows empirical probabilities. The dots represent the reliability diagram, and the lines show the best-fit logistic curve and beta curve. Note that the logistic sigmoid is a good fit for underconfident scores but not for overconfidence. The figure has been adapted from Niculescu-Mizil and Caruana (2005), and the beta curves have been added.
e.g., ROC analysis (Lachiche & Flach, 2003) but this would have to be repeated each time the skew changes. The great advantage of post-calibration is that it only needs to be done once -in a sense, it optimises all possible decision rules in one go.

Common forms of miscalibration, and how to fix them
There are many reasons why a probabilistic classifier might produce miscalibrated scores, and hence many ways in which miscalibration manifests itself, but two main types stand out: underconfidence and overconfidence. In this section we look at some examples and introduce two mitigation techniques. Figure 3, taken from Niculescu-Mizil and Caruana (2005), shows two typical examples. In both cases the points in the reliability diagram are far from the diagonal, although the effect is smaller in the figure on the right.
What do we see in the left figure? It is quite natural to give precedence to vertical information in such graphs, so you might be inclined to say "The points on the left are too low, and the points on the right are too high". But keeping in mind that the predicted probabilities on the x-axis are under our control but not the empirical probabilities on the y-axis, a more 'actionable' way to express this is The lower points are too far to the right, and the higher points are too far to the left. In other words, the points have a tendency to sit too close to the midpoint on the x-axis. This is the typical pattern displayed by an underconfident classifier, which thinks it's worse at separating classes than it actually is.
Hence, to mitigate this, we need to pull predicted probabilities away from the centre. As the left plot in Figure 3 shows, this can be neatly modelled by a sigmoidal Here, s is the uncalibrated score produced by the classifier and c gives the logistically calibrated score. m and w are the two parameters of the logistic family, which determine the point where c(s) = 0.5 and the slope at that point, respectively. They can be estimated from the points in the reliability diagram in order to find the best fit. In this case they can be obtained analytically as the mean of the classwise average scores, and the difference between those two means in proportion to the score variance (P. Flach, 2012).
The fitted logistic curve thus establishes a calibration map which transforms uncalibrated scores s into calibrated scores c(s). Even though the calibration map doesn't map to empirical probabilities, plotting it over the reliability diagram allows us to see clearly that if we project each point in the reliability diagram vertically onto the calibration map, and replace its x-value with the corresponding y-value of the projection, we end up with points on or very close to the diagonal, and hence near-perfectly calibrated scores (Figure 4).
The logistic curve is widely used as a 'squashing function', compressing values on a possibly unbounded scale into the [0, 1] interval. Following J. Platt (2000) it is often used as a way to convert scores from a Support Vector Machine into probabilities. Technically this isn't calibration as SVM scores are not probabilities but (signed) geometric distances from the decision boundary -this is also called scaling to emphasise the difference (hence the popular name 'Platt scaling'). The parametric form of the logistic map can be derived from first principles by assuming that within each class the uncalibrated scores are normally distributed with the same variance.
The other common form of miscalibration is overconfidence, as exemplified in Figure 3(b,c). An overconfident classifier thinks it's better at separating classes than it actually is. Hence we need to make predicted probabilities less extreme by pushing them toward the centre. The paper we took this figure from (Niculescu-Mizil & Caruana, 2005) also fitted a logistic curve to this reliability diagram Figure 3(b), because they were investigating the effect of Platt scaling in a wide range of scenarios. But we see clearly that the fit is rather poor, and using this logistic curve as a calibration map is likely to make matters worse. In this particular case we would be looking for something that can produce an inverse sigmoidal curve. What would be a principled way to achieve this?
One approach that works well is to model the classwise scores with Beta distributions . These assume random variables bounded in [0, 1] which is exactly what we need for posthoc calibration. Beta distributions can easily model the skewed distributions resulting from overconfident classifiers, as demonstrated in Figure 3(b).Mathematically, these curves have three parameters: This additional degree of freedom allows Beta calibration to produce both sigmoidal and inverse-sigmoidal calibration maps. It can even fit the identity map (a = b = 1, c = 0), which means that Beta calibration can recognise that scores are already calibrated. In contrast, applying logistic calibration to a calibrated classifier will decalibrate it. While Beta calibration can achieve many shapes of calibration maps, it is still a limited parametric family. Methods to fit richer calibration map families will be discussed in Section 5.

Multiclass calibration
The examples we have seen so far all relate to binary classification. Is it straightforward to generalise calibration concepts and methods to more than two classes? The answer to this question is somewhat involved. Some ideas do generalise quite easily: for example, we can model per-class scores by multivariate distributions such as Dirichlet distributions . Some other ideas don't generalise easily at all: for example, a multiclass generalisation of isotonic regression is not straightforward because rankings are inherently bipartite. Such approaches therefore need to be approximated by considering classes in a pairwise or one-versus-rest manner. This helps to explain why there is divergence even at a definitional level. There are at least three different ways of defining what it means to be calibrated in a multiclass setting. They are equivalent for binary classification but increasingly stronger for more than two classes, 2 and can be summarised as follows: • Confidence calibration: only consider the highest predicted probability. • Classwise calibration: only consider marginal probabilities. • Multiclass calibration: consider the entire vector of predicted probabilities.
We will use this terminology throughout the paper to avoid confusion.
Confidence calibration was proposed by Guo, Pleiss, Sun, and Weinberger (2017), although not under that name. It requires that among all instances where the probability of the most likely class is predicted to be α, the expected accuracy is α. Let X denote the instance space and P Y the probability K-simplex, then a probabilistic classifier f : X → P Y is confidence-calibrated, if for any confidence level α ∈ [0, 1], the actual proportion of the predicted class, among all possible instances x being predicted this class with confidence α, is equal to α: Here, S j denotes the j-th dimension of f(X). Classwise calibration, proposed by Zadrozny and Elkan (2002), requires that all one-vs-rest probability estimators obtained from the original multiclass model are calibrated. Formally, a probabilistic classifier f : X → P Y is classwise-calibrated, if for any class i ∈ {1, . . . , K} and any predicted probability value s ∈ [0, 1] for this class, the actual proportion of class i, among all possible instances on the random variable X getting the same prediction on class i, is equal to s: Multiclass calibration, also called calibration in the strong sense (Widmann, Lindsten, & Zachariah, 2019), is the strongest form of calibration for more than two classes, subsuming the previous two definitions. A probabilistic classifier f : X → P Y is multiclass-calibrated if for any prediction vector s = [s 1 , . . . , s K ] ∈ P Y , the proportions of classes among all possible instances on the random variable X getting the same prediction f(X) = s are equal to the prediction vector s: For practical purposes, the conditions in these definitions need to be relaxed. This is where binning comes in. Once we define the bins, we can draw a reliability diagram as in the two-class case. For classwise calibration, we can show per-class reliability diagrams or a single averaged one. One way to assess the degree of calibration is by means of the gaps in the reliability diagram. These topics will be explored in Section 4. We will first take a closer look at the important concept of proper scoring rules in the next section. Proper scoring rules are instance-wise evaluation measures for and classes (5,5,0); and the remaining 10 instances with probabilities (0.3,0.6,0.1) and classes (2,7,1). This classifier is classwise-calibrated but not confidence-calibrated. There are 20 instances with confidence level 0.6 and accuracy 0.6 (5+7=12 out of 20), but the remaining 20 instances have confidence 0.4 and accuracy 0.35 (4+3=7 out of 20). The key idea of this construction is that classwise calibration considers the instances with 0.4 predicted for class 1 as a single group, but confidence calibration looks among them only at those instances for which 0.4 is the highest probability -e.g., it does consider (0.4,0.3,0.3) but not (0.4,0.6,0.0). probability estimates that avoid the need for score binning. As a result they cannot measure the degree of calibration directly, but through decomposition results, we will show how the scores can be decomposed into various components, including the calibration loss.
3 From proper scoring rules to calibration As early as 1950 researchers were interested in scoring functions that would evaluate probabilistic forecasts without influencing the forecaster into making undesirable predictions (Brier, 1950), thus keeping the forecaster "honest" while encouraging useful forecasts. In the late 1960s the term proper scoring rule was already in use for score functions whose computation was based on a forecaster's probabilities and the actual occurrence or not of the corresponding events (Winkler, 1969). Informally, a scoring rule is said to be proper if optimal values are obtained by the forecaster predicting the true probabilities of the events. Proper scoring rules and their ability to induce useful and accurate forecasts also lend themselves to game-theoretic interpretations, as discussed in the seminal work of Savage (1971).
Before diving into details, let us introduce the notation. In a multiclass classification task with K classes, let the true class of an instance be a vectorẏ = [y 1 , . . . , y K ], where y j = 1 when the true class is j, otherwise y j = 0. Additionally, let s = [s 1 , . . . , s K ] be a class probability vector obtained from a classification model for an instance, i.e. s j ≥ 0, j = 1, . . . , K and ∑ K j=1 s j = 1. A scoring rule φ (s,ẏ) is a non-negative measure of how well the estimated probability vector s matches the true class vectorẏ. We assume that lower values of φ (s,ẏ) are better. 3 Popular scoring rules include Brier score φ BS and log-loss φ LL , which are defined as follows: (1) Our Brier score definition ranges between 0 and 2, agreeing with Brier's original definition (Brier, 1950), although it is now common for half this quantity to be called Brier score. While scoring rules evaluate the loss incurred by the class probability estimates for a single instance, we are usually interested in evaluating the performance of a model on test data. Thus, given a test dataset, we can calculate the empirical loss as the average instance-wise loss across the data. Suppose the class labelsẏ are drawn from the true distribution q over classes. A scoring rule φ is proper if its expected value on probability vector s andẏ is higher than (i.e., worse) or the same as its expected value on q andẏ, that is if Eẏ ∼q φ s,ẏ ≥ Eẏ ∼q φ q,ẏ , and it is strictly proper if and only if both sides of the expression being equal implies s = q. Both Brier score and log-loss are strictly proper scoring rules.
Among proper scoring rules, log-loss in particular is frequently used as the training loss of machine learning methods such as neural networks, often under the name of cross-entropy. It is also the loss function used by most of the calibration methods discussed in Section 5, including Platt scaling, temperature scaling and its variations (vector and matrix), beta calibration and Dirichlet calibration. A notable exception is isotonic calibration, which optimised Brier score.
At the instance level, log-loss only depends on the predicted class probability for the true class (as all other classes y j are zero) and it might not be obvious why it is a proper scoring function. For example, one could argue that it does not matter whether the model predicts [0.8, 0.2, 0.0] or [0.8, 0.1, 0.1] on an instance of class 1, as log-loss would be − ln(0.8) in both cases. However, one needs to keep in mind that properness is defined as an expectation over a population. For instance, suppose that, for a population of instances, the true probability is [0.8, 0.2, 0.0]. In this case, the expected log-loss will be −(0.8 log(s 1 ) + 0.2 log(s 2 )), which can only be minimised by predicting the probability vector [0.8, 0.2, 0.0], satisfying the properness condition. Note that log-loss can be dominated by cases where the true class is predicted with low probability: in the extreme case of a single instance with zero probability for the true class the loss is infinite.

Decompositions of proper scoring rules
When proposing the forecast evaluation that would later be known as Brier score, Brier mentioned that it could not be "gamed", i.e. in order to obtain low scores, the forecaster has to produce honest, useful and correct predictions. Later research focused on why this was true for Brier score and other proper scoring rules. Sanders (1963) showed that Brier score corresponds to the sum of two aspects of probability evaluation: validity and sharpness, terms introduced by Miller (1962) and Bross (1954), respectively. Validity, later known as reliability (Murphy & Winkler, 1977), is now often called calibration loss . It refers to the fit between the forecasts and the frequency of occurrence of the event, which means that it is a joint property of the predictions and the events. Sharpness, which is now commonly called refinement loss and was also known as resolution (Murphy & Winkler, 1977), is the loss due to predicting the same probability for instances from different classes. DeGroot and Fienberg (1983) showed that these two terms make up proper scoring rules in general, and that probabilistic predictions should minimise refinement loss subject to calibration.
We now formally introduce such proper scoring rule decompositions. Let X anḋ Y = [Y 1 , . . . ,Y K ] be multivariate random variables, respectively corresponding to the features and the class of a randomly picked instance, where Y j = 1 if the instance is of class j, otherwise Y j = 0, for j = 1, 2, . . . , k. Given a scoring classifier, class probability estimator or probability forecaster f, we denote by S = [S 1 , S 2 , ..., S k ] = f(X) the vector output of f for random feature X, where S is a random vector due to its dependence on X. The expected value of proper scoring rule φ with respect to S andẎ is then E φ S,Ẏ . Table 2: Example dataset with three classes and three features. Column Q (i) shows class posteriors given by the optimal model with Q 1 = 0.25X 1 , Q 2 = 0.25X 2 and Q 3 = 1 − (Q 1 + Q 2 ). Column S (i) corresponds to estimated class posteriors S = f (X), which are given by S 1 = 0.3X 3 , S 2 = 0.1X 2 and S 3 = 1 − (S 1 + S 2 ). Finally, column C represents calibrated probabilities.
Consider a classification test set of 10 instances belonging to three classes (K = 3) and described by 3 features, as shown in column X (i) of Table 2. Suppose instances 1, 2, 3 and 5 belong to class 1, i.e. Y 1 = 1, instances 4, 6, 7, 8 belong to class 2 and the rest belong to class 3. Note that in this example, the optimal class posteriors Q (i) are given, however this is not generally the case. Additionally, the sample is representative by design, with average Y (i) , among instances with the same feature values, exactly agreeing with Q (i) . Given columns S (i) and Y (i) from Table 2, and using Equations (1) and (2), by averaging over the 10 instances, we get a mean Brier score of 0.71 and mean log-loss of 1.12. Now let C = [C 1 ,C 2 , . . . ,C K ] be yet another random vector, where C j = E[Y j |S], i.e. C j represents the actual proportion of class j given all instances which received the same estimate S from model f. The decomposition of proper scoring rule φ into calibration loss and refinement loss is then the sum of expected loss between S and C and expected loss between C and Y (Bröcker & Smith, 2007;: where d : P Y × P Y → R is the divergence associated to proper scoring rule φ . For log-loss and Brier score, d has been shown to correspond to the Kullback-Leibler divergence and the mean squared difference, respectively .
The definition above is given based on expected population loss. In practice, we would be calculating these quantities on test data, as we generally do not have access to the whole population. Thus, we actually calculate an empirical loss. But assuming that test data is representative of the whole population and that there is a uniform distribution over the test instances and zero probability elsewhere, empirical loss can be interpreted as a special case of expected loss and all decompositions derived for expected loss also apply to empirical loss .
In our example in Table 2, the first four instances share the same model scores S = [0.9, 0.1, 0.0], with the first three instances belonging to class 1 and the fourth to class 2. Thus, for these instances, C = [0.75, 0.25, 0.0]. The other six instances also share a score vector, with 1 instance from class 1, three from class 2 and 2 instances from class 3. As a result, they share the same calibrated probabilities C = [1/6, 3/6, 2/6]. Given these values and considering Brier score, calibration loss is 0.19 and refinement loss is 0.52, which sum up to the Brier score of 0.71, as expected. For log-loss the decomposition is 1.12 = 0.29 + 0.83.
It is easy to see that a function that maps S to C, known as a calibrator in Section 5, could potentially reduce calibration loss to 0, consequently decreasing proper scoring rule loss. Refinement loss, on the other hand, is only zero if there are no ties between instances of different classes, i.e. they do not share the same value for S. If that is the case, it is possible to map S to C such that it is perfectly confident and correct, i.e. C j = Y j . Now suppose we knew the optimal model that outputs the true posterior class i.e. Q j is the true proportion of class j among instances with feature values X. Then the expected loss according to proper scoring rule φ can be decomposed into the sum of expected divergences between S and Q and Q and Y: The first term in the sum is called epistemic loss (Senge et al., 2014) and is the loss due to our model f(X) not being optimal. The second term is called irreducible or aleatoric loss (Senge et al., 2014) and is the loss of the optimal model. Going back to the example in Table 2, for Brier score, epistemic loss is 0.26 and irreducible loss is 0.45. For log-loss the decomposition is 1.12 = 0.48 + 0.64. The irreducible loss is only zero if the attributes of every instance X carry enough information to uniquely define the labelẎ. It is thus not possible to come up with a procedure to reduce the overall loss based on it. Additionally it would be unrealistic to do so based on epistemic loss. We are then naturally drawn to calibration loss as it is simple to interpret (we want our predicted probabilities of occurrence of an event to match the actual frequencies of occurrence) and also because we can easily estimate it with enough data. Thus, as discussed in the following section, visualisation and estimation of miscalibration have received considerable attention in the literature of probability evaluation and machine learning.

Evaluation and visualisation of classifier calibration
In this section we present a range of approaches to evaluate and visualise calibration, and discuss the advantages and disadvantages of each. In Section 4.1 we explore the first steps towards measuring miscalibration, starting from the early work on weather forecast calibration, and discuss various approaches to visually inspect miscalibration. Some of those early approaches have been later adapted and proposed as new calibration metrics which are discussed in the following sections. We start with binary calibration in Section 4.2 which will serve as a building block for the two multiclass calibration measures discussed in Sections 4.3 and 4.4.

Visualising calibration
Several visualisation techniques have been proposed for easier inspection of the reliability of predictions at different score ranges. In this section we summarise a range of approaches that have been proposed in the literature, from simple tabular inspection to the more recent reliability diagrams (see Bröcker and Smith (2007) for an extended discussion of reliability diagrams).
Starting from the binary case, the basic idea has been to show the relation between a particular predicted scoreŝ ∈ [0, 1] for the positive class of a probabilistic classifier and the respective observed proportion of positives, which we denote byȳ(ŝ). In order to compute a observed proportion of positives we require multiple samples with the same scoreŝ. However, given that the scores are continuous variables, the probability of getting multiple samples with the same score is almost zero. For that reason, the score space is commonly discretised into M bins {B 1 , . . . , B M }, thus increasing the probability of having multiple samples per estimation range (perhaps by forcing each bin to have a minimum number of samples). Then, we can obtain M observed proportions of positivesȳ(B m ) instead of one per score valueŝ. See Table 1 for an early use of observed proportions of positives using equal-width bins of predicted probabilities.
Later work showed line plots instead of tabular data, with markers at the centre of each bin (Lichtenstein et al., 1977;Lichtenstein, Fischhoff, & Phillips, 1982;Murphy & Winkler, 1977;Sanders, 1963); occasionally including the number of samples in each bin next to the markers (See Figure 5a). Other authors showed the markers with size relative to the sample size (Hagedorn, Doblas-Reyes, & Palmer, 2005), or as a separate histogram next to the reliability diagram (Niculescu-Mizil & Caruana, 2005). Line plots facilitate visual inspection of the discrepancy of the observed proportions of positives against a perfectly calibrated model, which corresponds to the diagonal. However, positioning the markers at the centre of the bins can be misleading, as even perfectly calibrated scores may result in a visually noncalibrated reliability diagram with a deviation of up to half the bin width from the diagonal (Bröcker & Smith, 2007) (See Figure 6 for an example). This may happen in cases in which the scores are not evenly distributed in each bin. In order to alleviate this problem, later work centred the markers on the average predicted scores s(B m ) in each bin instead. There are two main methods to group the predicted scores into bins to build reliability diagrams. The first one, commonly called width binning, distributes scores into a number of bins of the same width, choosing bin edges accordingly (e.g., 10 bins [0, 0.1], (0.1, 0.2], . . . , (0.9, 1.0]). Another method, called frequency binning (also equal size or equal mass binning) groups the scores by keeping the same number of samples in each bin. Frequency binning can and will normally result in bins with different widths, but it ensures that all bins have the same "weight" when assessing the model's miscalibration.
Bin estimations have varying reliability, e.g., depending on the number of samples in the bin. One way to show this visually is by incorporating confidence intervals. One of the simplest methods is to assume that each bin is sampled from a binomial  distribution, and compute the corresponding confidence intervals of the observed proportion of positives (see Figure 7b). However, making the assumption of fixed bins, score averages and proportion of positives is unrealistic; unless the score distribution is uniform (see (Bröcker & Smith, 2007) for a detailed discussion). More accurate intervals can be obtained by using the consistency resampling method proposed by Bröcker and Smith (2007), which consists on sampling the scores with replacement several times in order to obtain multiple surrogate forecasts and observations and their respective quantiles. More recently, binary reliability diagrams have been extended to the multiclass setting. One method to show multiclass scores in a binary fashion consists in plotting only the confidence of the model for each sample (the highest score among all possible classes). This approach was already used for binary classification by Lichtenstein et al. (1977), reproduced here as Figure 5b. The figure shows a binary reliability diagram with scores in the range [0.5, 1] (with K classes the confidence is never lower than 1/K). Another example of the use of confidences in multiclass problems is the recent work of Guo et al. (2017), which shows the confidence for multiclass problems in the form of bar plots and the ECE and MCE metrics discussed below. Finally,

Evaluating calibration error: the binary case
We now proceed with discussing how to measure calibration error. We will use the three-class toy problem in Table 3 throughout. In this section we convert it to a binary classification problem by taking class 1 as positive and classes 2 and 3 as negative. We then apply equal-width binning to the class 1 probabilities. Table 4 Table 4 can be used to draw the reliability diagram shown in Figure 8, where we can see the red bars representing the calibration error at each bin.
Given the information about the bins in Table 4 we could calculate an average of the bin-wise calibration error, which leads us to binary estimated calibration error, as defined in Definition 1.
Definition 1 (Binary-ECE) Binary estimated calibration error (Roelofs, Cain, Shlens, & Mozer, 2021), or binary-ECE (P. Naeini, Cooper, & Hauskrecht, 2015), is the average gap across all bins in a reliability diagram, weighted by the number of instances in each bin: where M and N are the number of bins and instances, respectively. Binary-ECE is also commonly called binary expected calibration error, however this quantity is empirically estimated on a validation or test sample, which is why we prefer to call it binary estimated calibration error.    Table 4: Positive probabilities and corresponding instance labels separated into 5 bins. The probabilities were obtained by taking class 1 as the positive class in the multiclass problem in Table 3. To reduce the width of the table, a number followed by a superscript parenthesis X (Y ) indicates a list of number X repeated Y times.  Table 4. Figure 8 by taking the weighted mean of the sizes of these gaps. In this example, ECE binary = 0.1873.

Binary-ECE aggregates part of the visual information about calibration error in
Binary-ECE ranges from 0 to 1, with particular values including ECE binary = π 1 (proportion of positives) for a classifier that randomly outputs probability 1 for one of the classes, ECE binary = 0 for a perfect classifier that always predicts probability 1 for the correct class or for a classifier that constantly outputs positive probability equal to π 1 , and ECE binary = 1 for a classifier that always assigns probability 1 to the wrong class.
Instead of measuring how miscalibrated the model is on average, one might be interested in the worst case, in other words "how maximally miscalibrated is the model"? In this case, one might use the binary maximum calibration error (P. Naeini et al., 2015). In our example, Table 4 and Figure 8 show that the fourth bin has the largest gap, with its size corresponding to MCE binary = 0.48.
Binary-MCE can be very sensitive to bins with few instances, where the values ofȳ(B m ) ands(B m ) are calculated based on very little information. In extreme cases with only a single instance in a bin,ȳ(B m ) will be the instance's actual label (1 or 0), potentially resulting in a large gap that would have a small weight in binary-ECE, while being the whole value of binary-MCE, meaning that the model would be evaluated based on its performance for a single instance.

Classwise calibration error
We now proceed to settings with more than two classes and start by defining the estimated calibration error corresponding to a single class j in a multiclass task.
Definition 3 (Class-j-ECE) Given a multiclass task with K classes, class-j-ECE corresponds to the binary-ECE calculated by taking class j as positive and the other K − 1 classes together as a new negative class: where B m, j is the m-th bin of class j.
Once again we turn to our example in Table 3. Following Definition 3, we have already calculated class-1-ECE (0.1873) in our binary-ECE example. Now we need to calculate class-2-ECE and class-3-ECE. Tables 5 and 6 show the binary bins for classes 2 and 3, respectively, while the binary reliability diagrams of the three classes can be seen in Figure 9.  Table 5: Positive probabilities and corresponding instance labels separated into 5 bins. The probabilities were obtained by taking class 2 as the positive class in the multiclass problem in Table 3.  Table 6: Positive probabilities and corresponding instance labels separated into 5 bins. The probabilities were obtained by taking class 3 as the positive class in the multiclass problem in Table 3.
From the values in Tables 5 and 6 and following Definition 3, we get class-2-ECE = 0.147 and class-3-ECE = 0.2017. We can now define classwise-ECE .
Definition 4 (Classwise-ECE) The estimated classwise calibration error (classwise-ECE) is the average class-j-ECE across all classes: According to Definition 4, in our example classwise-ECE = (0.1873 + 0.147 + 0.2017)/3 = 0.1787. In our running example, MCE classwise = 0.48. Note that this is not the only way to define classwise-MCE. For example, one could be interested in the average maximum gap across classes, i.e. an average classj-MCE, which in our example would be (0.48 + 0.24 + 0.3)/3 = 0.34. As another variation, one could take the maximum class-j-ECE, which would then indicate the most miscalibrated class on average. In our example, this variation corresponds to class-3-ECE (0.2017).
Although classwise-ECE and MCE measure calibration error over all classes, they do not take into account the miscalibration that arises from every possible relationship between classes. For a true multiclass-ECE, we could bin the probability vectors in simplex space and then calculate the gaps between the average probability vector and the vector of class proportions in each bin. Although this seems like the right thing to do when evaluating multiclass calibration, it might not be efficiently computable with large numbers of classes, as the number of bins can be prohibitively high and most bins would likely be empty.
Similarly to binary-ECE, a value of classwise-ECE = 0 can be obtained by a classifier that constantly outputs the class proportions. For example, if a classifier always predicts 1/3 setosa, 1/3 versicolor and 1/3 virginica for Fisher's Iris dataset, the resulting classwise-ECE will be 0.

Confidence calibration error
As already mentioned, some calibration measures only consider a model's confidence, defined as the maximum value in the predicted probability vector, i.e. the probability given to the winning class. Prediction confidence is not a new idea and has been around since at least the 1970s. Lichtenstein et al. (1977) called it the halfrange method in the binary case (referred to as "two alternatives" in the paper) and it was also mentioned as one of the variations of the multiclass task, which the authors called "three or more alternatives". More recently it has been popularised by Guo et al. (2017).
To calculate confidence-ECE, we first bin the confidence values and, for each instance of each bin, we produce a binary value indicating if the classifier predicted correctly or not. Recalling the example from Table 3, the resulting confidence bins are presented in Table 7, wherep(B m ) and acc(B m ) are respectively the average confidence and prediction accuracy in bin B m , with the corresponding reliability diagram in Figure 10. Note that bin B 1 is empty, which demonstrates that confidence-ECE and confidence reliability diagrams are different from binary-ECE even on two-class problems.  Definition 6 (Confidence-ECE) Confidence-ECE is the average difference between accuracy and average confidence across all bins in a confidence reliability diagram, weighted by the number of instances in each bin: We then calculate confidence-ECE as the weighted mean of the gaps between average confidence and prediction accuracy at each bin, thus ECE confidence = 0.2117,  Table 7. while the maximum confidence calibration error (confidence-MCE) corresponds to the largest gap, i.e. MCE confidence = 0.3. As with binary-ECE and for the same reasons, confidence-MCE is very sensitive to small bins, but in this particular example, its value corresponds to the gap of the largest bin.
As we show in Section 5, there is a wide range of post-hoc calibration techniques in the literature, each one capable of handling different miscalibration patterns. Thus, it can be useful to first analyse a model's reliability diagram, as it allows us to diagnose model miscalibration, i.e. in what probability ranges it is underconfident or overconfident, and this can help choose an appropriate calibration method. In addition, any of the ECE measures discussed in this Section can be used to decide if a classifier actually needs to be calibrated, by testing the hypothesis that the model is already calibrated, as shown in Section 6. Finally, it is important to consider that all ECE/MCE measures can provide very different values given different number of bins, as shown in Figs. 1 and 2, and they can be minimised by predicting the overall class distribution, regardless of the given instance. Thus, it is good practice to use them together with the proper scoring rules presented in Section 3, to get a full evaluation of the probabilities produced by a model.

Calibration methods
In this section we provide a systematic review of standard approaches to calibrating classifiers through the construction of calibration maps. In particular, we focus on post-hoc calibration methods for classification, which can be used to adjust probability outputs separately from the initial training process. For each method, we cover the mathematical formulation, the objective function for learning the map, and the predictive function to calculate the class probabilities for a new instance. We include a few test cases to empirically analyse each method, and discuss their advantages and disadvantages. General guidance on each method's implementation is also discussed, addressing issues such as overfitting and computational effort. At the end of the section, we briefly describe some related work to classifier calibration, such as methods that can improve the calibration level during training time, methods that are designed for getting well-calibrated probability for other predictive tasks, and approaches that are designed for specific tasks in areas such as computer vision and natural language processing.

Preliminaries
We denote a calibration map as a function g : S Y → P Y . Here Y = {1, . . . , K} is the discrete space with K classes of the target variable. P Y denotes the probability vector space on Y, that is: P Y = {[s 1 , . . . , s K ] | s j ≥ 0, ∑ K j=1 s j = 1}. S Y represents the original output space of the (uncalibrated) classifier, which can take various forms depending on the formalisation of the classifier. For instance, for a typical probabilistic classifier, we have S Y = P Y . A one-vs-rest SVM might produce K-dimensional vectors in S Y = R K . Deep neural networks can also provide unnormalised vector outputs before the softmax is performed at the final layer. Calibration maps that work with such vector spaces are referred to as scaling approaches. The name suggests these approaches are used to scale the vector output into a probability output, which is quite useful for models like SVMs, as the hinge loss does not optimise probability estimates by default. However, other than the name and historical motivation, in modern applications, probability calibrators and scaling approaches can be used interchangeably, as the probability space and vector space can be transformed into each other by using the link function (e.g. softmax) and inverse link function (e.g. logit transform ).
In general, to obtain a calibration map, we will have a calibration set with uncalibrated probabilities and labels, denoted as C = {(s 1 , y 1 ), . . . , (s N , y N )}, and an objective function L(C) to optimise. Typically, the objective function is constructed using proper scoring rules, that is, L(C) = ∑ N i=1 φ (s i , y i ), and it can be optimised via various gradient descent algorithms.
Training Schemes: While the above notation suggested that the calibration map can be obtained by fitting a calibrator on a given hold-out calibration set, in practice a small training set and calibration set might lead to over-fitting thus limiting the performance of the calibrated model. A typical solution here is to introduce multifold dataset splits as introduced in (J.C. Platt, 1999). The author proposes to divide the training sets into three different folds and fit the model and calibration map in cross-validation. Two folds are used to train the uncalibrated model, and the model predictions on the last fold are collected and used to fit the calibration map. This training process thus ends up with three pairs of models and calibration maps. At test time each instance will be predicted with all three pairs, and resulting probabilities are averaged to give the final estimate. Alternatively, people have also used applied label smoothing (Müller, Kornblith, & Hinton, 2019) to reduce the level of overfitting and over-confidence. The idea is to have a weighted average between the original probability vector (either from the uncalibrated model or after a calibration method has been applied) and a uniform probability vector. Therefore, the final probability Fig. 11: The synthetic dataset used in the test cases. The left two figures shows the data distribution for each class respectively. The figure on the right gives the Bayesoptimal posterior probability for class 1.
vector will be pushed somewhat towards the uniform probability vector, which avoids overly high confidence for unsuitable cases.

Two-Class Test Cases
We designed some test cases to illustrate each calibration map's characteristics empirically. These test cases are designed with a known distribution and allow us to directly sample the instances. For ease of understanding, we consider a scenario with a univariate feature (x ∈ R), so that we can inspect the fitted functions and reliability diagrams by means of x-y plots. Figure 11 depicts the probability density functions for the synthetic two-class dataset, as well as the posterior class probabilities when predicting any new instances. The generative model is equally likely to produce a positive and a negative, and the distribution of the feature values are mixtures of two normal distributions within each class. Denoting the mixture components as H = 1 and H = 2, our generative model can be formally written down as: This generative assumption allows us to approximate the 'true' reliability diagram closely for every test case and provides better insights into each calibration map. Specifically, we generate a large number of random samples and use small bin sizes to approximate a smooth reliability diagram.
We consider three cases for binary classification, each of which may occur in practice. The first two cases are hypothetical over/under-confident scenarios using a Fig. 12: The reliability diagrams of the three uncalibrated classifiers. The left figure shows thef under case, where the classifier predicts a probability closer to 0.5 compared with the Bayes-optimal case (Fig. 11, right), resulting in a reliability diagram with steeper slope. The middle figure shows thef over case, where the predicted probabilities are pushed towards 0 and 1 respectively, resulting in a shallower reliability curve. The right figure is obtained with a MLP classifier (f MLP ), where the reliability diagram shows over-confident and under-confident predictions around different regions.
logistic regression model of the formf(x) = (1 + exp(−a · x)) −1 . Such a model puts the decision boundary at x = 0, which is nearly Bayes-optimal for the synthetic data. The model confidence can be moderated with the parameter a, and we will use the following two cases:f The third case is obtained with an MLP classifier as implemented by the scikit-learn Python package. The model is specified with a two layer structure with 128 hidden units per layer. The activation is selected as the ReLU function. The remaining settings are left at their default values. 10, 000 instances are sampled to train the model.
The smoothed reliability diagrams for these three cases are shown in Figure 12. In the under-confident case the output probabilities barely reach the outside of the interval [0.1, 0.9]. The reliability diagram shows a higher slope compared with the perfectly calibrated one (the diagonal). In contrast, the over-confident case has a shallower slope around the middle compared with the diagonal. It further causes the reliability diagram to have sharp transitions while approaching the extremes. For the MLP case, we can observe both under-confident and over-confident regions throughout the reliability diagram. This specific MLP classifier tends to be under-confident around s ∈ [0, 0.1] and s ∈ [0.65, 1], and mostly over-confident elsewhere.

Calibration for Binary Classification
We start with methods that can learn calibration maps for binary problems. In binary classification, probability estimates are scalars, so the calibration maps are functions mapping from [0, 1] to [0, 1]. Here we describe four widely applied methods in detail: empirical binning, isotonic regression, logistic calibration and Beta calibration. Other approaches will be be briefly mentioned at the end of this section.

Empirical Binning
Empirical binning (P. Naeini et al., 2015;Zadrozny & Elkan, 2001) is one of the simplest methods to build a calibration map. It directly connects to the previously introduced ECE measure, which evaluates the calibration level by calculating the empirical frequencies within a set of score intervals. Therefore, binning approaches can directly optimise a variant of ECE depending on how the binning scheme is selected.
For a typical setting, the empirical binning approach comes with the following parameters. (1)  (2) Probability estimates in the bins: a = {a 1 , . . . , a M }, where a m ∈ [0, 1] specifies the calibrated probability value in each bin. We usually assume that these bins do not overlap with each other. To make a prediction based on an uncalibrated probability s, empirical binning uses the following functional form: Here s ∈ B m means that the uncalibrated probability s falls within B m . Fitting a binning calibration map can be done by optimising a using ECE as a loss function: Hereȳ(B m ) represents the empirical frequency within B m as defined in the previous section. The equation hence indicates that we want to assign each a m according to the empirical frequency of the labels within each bin B m . We empirically analyse the binning approach with a simple setting of M = 10 equal-width bins. The results with the three test cases are shown in Figure 13. The binning approach performs well on most points, as the reliability diagram are close to the diagonal after calibration. However, it should be noted that the output probabilities can only take M different values. Therefore, while the final probabilities are calibrated, we can no longer distinguish instances that receive different predictions from the uncalibrated model. In other words, binning approaches can reduce the calibration loss at the cost of a higher grouping loss . Fig. 13: Examples of empirical binning calibration with 10 equal-width bins. As the binning approach can only give discrete outputs, we can observe the probabilities after calibration are no longer continuous and are only presented with 10 values or less (the under-confidence case has fewer values as there are no observations in bins closer to the extremes. The reliability diagrams show that the calibration method works well with all three test case, with most points being close to the calibrated diagonal. While here we illustrated the binning approach with equal-width bins, it is possible to use other binning schemes such as equal-frequency binning. For example, (P. Naeini et al., 2015) propose a Bayesian binning approach.
To summarise, the main advantages of binning approaches are as follows: (1) They can be used to directly minimise a specific variant of ECE, hence are useful when calibration loss is of primary concern. (2) Training is reasonably fast and straightforward. (3) Given its non-parametric nature, it does not have any constraint on the form of the calibration maps and therefore can capture arbitrary shapes according to the given bins. In addition, other binning strategies can also be applied to deal with different datasets and uncalibrated models.

Isotonic Calibration
Calibration by means of isotonic regression is another widely used non-parametric approach (Barlow & Brunk, 1972;M.P. Naeini & Cooper, 2016;Niculescu-Mizil & Caruana, 2005). The isotonic approach was originally proposed to solve univariate regression tasks where the function were required to be monotonic. In the case of probability calibration, if we assume the uncalibrated model has a monotonic reliability diagram, then isotonic regression is a suitable approach to achieve a better level of calibration.
Isotonic regression achieves a monotonic fit by estimating a set of non-decreasing constant segments, corresponding to a set of bins of varying width. Isotonic regression can therefore be described with the following parameters: (1) Bin boundaries: As indicated by the parameters, isotonic regression is quite close to an empirical binning approach. The main difference is that instead of having a predefined set of bin edges, isotonic regression learns these bin boundaries from the data. As a result, isotonic regression can have an variable number of bins depending on the training set. To calibrate a probability s, isotonic regression uses the following predictive function: The three test cases on istonic regression are shown in Figure 14. To compare with the empirical binning approach again, while in the empirical case we have a constant prediction within each bin, we can see the prediction of the isotonic approach depends on the two values on the bin edges. In the case where the two bin edges do not share the same value, isotonic regression performs linear interpolation to calculate the predicted value. This behaviour is due to the way that the isotonic approach is estimated. To ensure the estimated function is monotonically increasing, the learning algorithm starts with the first bin edge as the minimal feature value (0 in the case of an isotonic calibration) and extends the following bin edges until it sees a higher target value (this is also referred to as 'pooling adjacent violators' (Fawcett & Niculescu-Mizil, 2007)). It can be proven that, with monotonic sets of b and s, the learning algorithm is equivalent to optimising the following loss (Ayer, Brunk, Ewing, Reid, & Silverman, 1955): Therefore, when used as a probability calibration map, isotonic regression minimises the Brier score on the training set. Instead of applying isotonic regression directly,  (Allikivi & Kull, 2019) propose a Bayesian approach to improve isotonic regression, with demonstrated improvements on binary tasks. Isotonic regression is a compelling approach for probability calibration, with the following advantages: (1) When the monotonic assumption is suitable, isotonic regression can find the optimal bin edges for Brier score on the training sets, which is also known to give the convex hull in ROC analysis. (2) The non-parametric nature avoids catastrophic model misfit. On the other hand, isotonic regression has some drawbacks also: (1) By predicting constant values within bins, it inevitably increases grouping loss. (2) When the uncalibrated model has a non-monotonic reliability diagram, isotonic regression can only give sub-optimal results (i.e. large grouping loss).
(3) While it performs well on large datasets, isotonic regression's training time and memory consumption are also high on large datasets. (4) Isotonic regression can result in the first and last bins having full confidence (0 and 1), which can be problematic for certain datasets and evaluation metrics (e.g. log-loss). It is therefore common to clip the outputs from isotonic regression with a small ε (i.e., 0 to ε and 1 to 1 − ε).

Platt Scaling
Platt scaling is probably one of the most widely known approaches for probability calibration, partly due to the popularity of SVMs around the year 2000 (J. Platt, 2000). As SVMs are optimised with hinge loss, they can only output scores on the samples based on the estimated margins. Given that the margins are real scalars by definition, John Platt proposed to transform the scores into probability estimates with logistic regression. Platt scaling hence has the same parameters as a univariate logistic regression model: a shape parameter w ∈ R, and a location parameter b ∈ R. The predictive function is then: The parameters can be estimated by optimising the log-likelihood on the training set, so Platt scaling can be seen as optimising log-loss in the calibration context: Platt also included a technique to prevent overfitting and improve the generalisation of calibration, which is introduced as one of the training schemes at the beginning of this section. The test results are shown in Figure 15.
In general, Platt scaling is a practical calibration approach with the following advantages: (1) As it is based on logistic regression, implementation is straightforward.
(2) The standard logistic regression has a convex loss. The overall training process can, therefore be quite fast. On the negative side, Platt scaling has two main drawbacks: (1) The calibration map is restricted to a sigmoid shape, which effectively pushes probabilities away from the centre and may lead to over-confidence. (2) By definition, the logistic regression model considers the input space to be a real scalar space. While such an assumption is suitable for the margins obtained from an SVM, it is less appropriate for probabilistic classifiers, as the input is bounded by the interval [0, 1]. Hence, certain transformations are required when applying Platt scaling to calibrate probabilistic classifiers, such as the logit transform.
(a) Test case 1: under-confidence (b) Test case 2: over-confidence (c) Test case 3: MLP classifier Fig. 15: Examples of the Platt scaling approach. While it improves the underconfidence case well, it fails to do much with the over-confidence case. This is due to the fact that the sigmoid shape can not push the probabilities towards the middle hence can not fix over-confidence. Such result can also be observed with the MLP test case, where Platt scaling actually makes the level of calibration worse around several regions.

Beta Calibration
Beta calibration is specifically designed for probabilistic classifiers and alleviates both drawbacks of Platt scaling . While the latter can be derived from first principles by assuming that within each class the scores are normally distributed with the same variance, Beta calibration instead assumes two Beta distributions. This gives a richer family of calibration functions with three parameters: two shape parameters a, b ∈ R, and a location parameter c ∈ R. The calibration function is then given as: In comparison with Platt scaling, Beta calibration is a bivariate logistic regression model, where the two features are ln s and ln(1 − s) respectively. Similar crossvalidation training is also adopted as proposed in . Given its close relationship to logistic regression, Beta calibration also optimises the log-loss and the objective function can be given with the log-likelihood: Figure 16 demonstrates Beta calibration on the three test cases. The advantages of Beta calibration include: (1) Compared with Platt scaling, it allows a richer family of calibration maps including inverse sigmoids and the identity map. The latter is particularly useful to prevent over-calibration and apply unnecessary adjustments to already calibrated probabilities.
(2) Like with Platt scaling, implementation is straightforward. (3) With the Beta assumption, the calibration map supports any twoclass probabilistic classifiers, and the calibration map is learnt from a set of functions that map from [0, 1] to [0, 1]. However, Beta calibration's main drawback is that it can only model specific calibration maps, so if the original classifier is severely uncalibrated and requires a complicated calibration map, it might be preferable to choose non-parametric methods instead.

Calibration for Multi-class Classification
We now proceed with calibration maps that can work natively with a multi-class classification task, without the need for binarisation. We define a three-class test case for the purpose of examining multi-class calibration with a multi-layer perceptron (MLP). We modify the previous synthetic dataset to add an additional class, such that all classes are equi-probable and the distribution of the feature for the instances of class 3 is Gaussian also: Here we can see that the reliability diagrams after calibration are almost identical for the over-confidence and underconfidence test cases. This observation is because the Beta calibration method fits the map on the logarithm of the uncalibrated probabilities, and therefore reverts the sigmoid functions of the pseudo-models in both test cases. The calibration method then finds similar solutions as the pre-sigmoid parts are both linear models on the feature. This result suggests that the Beta calibration method can effectively fix the over/under-confidence caused by a sub-optimal linear-sigmoid operation. We visualise the calibration maps in the probability simplex (one for each class). An example can be seen in the top row of Figure 17, where the heat maps indicate the change of probability for each class after calibration. For the figure on the left, each point within the simplex represents an uncalibrated probability vector, a positive value (i.e., red colour) on that point indicates that the calibration map increases the probability value of class 1 in the vector and a negative value (i.e., blue colour) shows that the probability value on class 1 is reduced. The white line indicates where the probability values for class 1 remain (almost) unchanged. Class 2 and class 3 calibration maps are also depicted. The bottom row of each figure shows the class-wise reliability diagrams.

Temperature Scaling
Temperature scaling has become one of the default approaches to provide bettercalibrated probabilities, particularly in deep learning research (Guo et al., 2017;Hinton, Vinyals, Dean, et al., 2015). Instead of simply applying the softmax operation at the last layer to obtain a probability vector on the classes, Temperature scaling assumes a single temperature parameter t ∈ R and applies a linear operation before the softmax. Denoting z = [z 1 , . . . , z K ] ∈ R K as the K-dimensional real vector before softmax, the probability output after Temperature scaling is given as: Therefore, conventional softmax can be seen as the case of scaling with a fixed temperature of t = 1. If we want to apply Temperature scaling to a generic probabilistic model where z is not accessible, we can also use the logit transform on the uncalibrated probability vector to obtain a real vector: Here, K is selected as the reference class to compute the probability ratio with other classes. The parameter is also normally estimated with the log-loss, and the objective function is given as: Figure 17 gives the results on the MLP test case. The most distinctive characteristic of Temperature scaling is that it only has a single parameter, which can be seen as both an advantage and a disadvantage. On the positive side, a single parameter restricts the space of calibration maps and can prevent overfitting for small datasets with many classes. On the negative side, Temperature scaling can be sub-optimal when the function space of the calibration maps does not include the right reliability diagram.

Vector Scaling
Where Temperature scaling only has a single parameter across all classes, it is natural to extend the parameters to support a richer form of calibration maps. Vector scaling (Guo et al., 2017) allows a different temperature for each class, denoted as w ∈ R K , as well as adding a set of intercept parameters b ∈ R K for the K classes. The predictive function is given as (z can also be obtained with the logit transform for generic probability classifier, as in Temperature scaling): Fig. 18: Class-wise calibration maps and reliability diagrams for the MLP classifier with Vector scaling. The most obvious change from Temperature scaling is that now the calibration maps are different for each class. However, the calibration maps still have a circular shape as Vector scaling only adjusts one dimension of the logit vector for each class. As a result, the reliability diagram is close to the ones of Temperature scaling. Some minor improvements can be seen with class 3, where Vector scaling does not make it quite as bad as for Temperature scaling.
And the objective function to optimise log-likelihood is similar to the one for Temperature scaling, but with more parameters: The test result is given in Figure 18. Vector scaling can be seen as a middle point between the quite restrictive Temperature scaling and the general approach of Matrix scaling discussed below. Hence it balances the risk of overfitting and the richness of available calibration maps.

Matrix Scaling
Matrix scaling (Guo et al., 2017) removes all the parameter constraints on Temperature scaling and Vector scaling. Similar to a fully connected layer, it has a matrix parameter (w 1 , · · · , w K ), w j ∈ R K together with the intercept parameter b ∈ R K . The predictive function is (z can also be obtained with the logit transform, as in Temperature scaling): Fig. 19: Class-wise calibration maps and reliability diagrams for the MLP classifier with Matrix scaling. As Matrix scaling is capable of providing fully linear adjustments on the logits for each class, we can see the class-wise calibration map no longer has the circular shape. While there are still minor improvements on the reliability diagram of class 1 and class 2, class 3 has gained a significant improvement. and the objective function is: As indicated in Figure 19, Matrix scaling can support a broader family of calibration maps than Vector scaling and Temperature scaling, but may be vulnerable to overfitting as it can be seen as another fully connected layer.

Dirichlet Calibration
Dirichlet calibration is the multi-class extension of Beta calibration . Assuming Dirichlet distributions for the predicted probability vectors within each class, Dirichlet calibration is determined by a set of coefficient vectors (w 1 , · · · , w K ), w j ∈ R K , and a set of intercepts b ∈ R K . The calibrated probability on the j-th class is obtained as: This function can be seen as a K-dimensional logistic regression on the logprobabilities (i.e., the sufficient statistics of the Dirichlet distribution). Therefore, to apply Dirichlet calibration to a deep neural network, one can first obtain a probability vector using the softmax function, then apply Dirichlet calibration as with other Fig. 20: Class-wise calibration maps and reliability diagrams for the MLP classifier with Dirichlet calibration. The overall results on the class-wise reliability diagrams are close to those obtained with Matrix scaling. The major differences are seen in the calibration maps, where we can clearly observe a local region for the changes on class 3. Importantly, this region for the Dirichlet calibration approach doesn't cover the area where the predicted probability of class 3 is close to 1. This is more reasonable compared with Matrix scaling, as both the Bayes-optimal predictions and the MLP predictions for class 3 are capped around 0.8.
probabilistic classifiers. The objective function is: The test results are given in Figure 20. Similar to Beta calibration, one of the advantages of Dirichlet calibration is that it also supports the identity map, so it can also prevent over-adjusting calibrated results. As the number of parameters is similar to that of Matrix scaling, the Dirichlet calibration can also overfit on small datasets. The authors propose the ODIR (Off-Diagonal and Intercept Regularisation) approach to address this issue further and report various performance improvements in their experiments.

Extended methods for post-hoc classifier calibration
In this section we discuss more recent work extending the standard calibration methods discussed above. Leathart, Frank, Holmes, and Pfahringer (2017) aim to build calibration maps locally instead of a global calibration map and proposes using modified logistic model trees to build an ensemble calibration method. A decision tree is learnt to separate the original feature space into multiple regions, where a local calibrator can then be estimated using the corresponding outputs and labels. Kumar, Liang, and Ma (2019) propose a combined approach of scaling and binning methods to achieve better calibration with smaller calibration sets. Instead of calculating the label frequency in binning methods, the authors show that using the average value of a pre-fit continuous calibration map gives better calibration. The authors also indicate that a debiased estimator can provide better calibration error in sample complexity. Wang, Li, and Dang (2019) discuss how to build flexible univariate non-decreasing calibration maps from shape-restricted polynomial regression models. The resulting method provides a useful alternative when methods like Plat scaling and Beta calibration cannot approximate the actual reliability diagram. Wenger, Kjellström, and Triebel (2020) investigate non-parametric post-hoc approaches that can support richer forms of calibration map for a multi-class setting. The idea is to employ the framework of Gaussian processes and model the calibration map as latent distribution of functions. The family of calibration maps can thus be richer with the selection of suitable kernels. Zhang, Kailkhura, and Han (2020) propose an approach to build an ensemble of base calibrators, which can improve the capacity of the calibration maps while preserving the accuracy. The authors also adapt kernel density estimation as an alternative approach to evaluating calibration error. Ma and Blaschko (2021) consider the confidence calibration setting and propose to improve a calibration map with a ranking model. The authors demonstrate that the ranking model can be used to maintain the performance of the uncalibrated classifier in terms of precision and false positive rate. Patel, Beluch, Yang, Pfeiffer, and Zhang (2021) tackle the issue of applying class-wise binning calibrators to a multi-class setting. An iterative update method is provided to adjust the bin edges to better calibration, and a sample-sharing approach among similar classes is also introduced for better sample efficiency.

Methods that can improve calibration during training time
While post-hoc calibration can be applied to most existing classifiers, it is of practical interest to train well-calibrated models in the first place. Here we briefly mention some training-time calibration methods. Kumar, Sarawagi, and Jain (2018) consider a regularisation approach with kernel mean embedding. The idea is to add a differentiable regularisation term concerning the goodness of calibration, where the kernel mean of the scores is calculated as an approximation of the calibration error. The overall objective function allows the model to achieve better calibration during the training phase. Thulasidasan, Chennupati, Bilmes, Bhattacharya, and Michalak (2019) show that the Mixup strategy can improve the calibration level when introduced during the training phase. Vicinal points are created by combining existing data points and labels, and then added to the training set. The authors suggest that the improvement in calibration is due to the augmentation effect and label smoothing effect, both from the mixup process and act as a form of regularisation. Kristiadi, Hein, and Hennig (2020) consider a Bayesian approach where a Gaussian approximation distribution is fitted to the last layer's weights of a ReLu network. The authors demonstrated that the method could reduce the over-confidence problem in a classification setting, particularly on data points not commonly seen in the original training set. Wen, Tran, and Ba (2020) propose an efficient ensemble approach that can train multiple deep networks with lower computational and memory costs. The authors show that the obtained ensemble achieves better calibration on out-of-distribution samples at test time.
Other than deep networks, some recent work achieves better calibration on Bayesian nonparametric methods. Milios, Michiardi, Rosasco, and Filippone (2018) propose an alternative approach to train Gaussian Processes for classification tasks. While the traditional GP classifier relies on sigmoid or probit link functions and requires suitable approximated inference schemes to ensure good performance, the authors propose a modified Dirichlet link function to ensure the level of calibration as well as scalability. Tran, Bonilla, Cunningham, Michiardi, and Filippone (2019) demonstrate that convolution Gaussian process classifiers can be miscalibrated, and propose a solution to mitigate the issue.

Methods for probability calibration for other predictive settings
The concept of calibration can be naturally generalised to predictive settings other than classification. The most straightforward extension is the calibration of regression outputs. As in the classification scenario, there are multiple definitions of calibration for regression models. The standard definition of calibration comes from the field of quantile regression (Koenker & Hallock, 2001), where being calibrated means that the predicted quantile matches the marginal distribution of the target variable. As in the case of classification, there are methods designed for training calibrated quantile regression as well as post-hoc approaches that calibrate pre-trained models. Fasiolo, Wood, Zaffran, Nedellec, and Goude (2020) provide an approach to train generalised additive regression models with calibrated quantiles. Cui, Hu, and Zhu (2020) propose an approach to train deep regression models with better-calibrated quantiles, where the model parameter is first fit with log-loss and then updated with a loss based on the maximal mean discrepancy (Gretton, Borgwardt, Rasch, Schölkopf, & Smola, 2012). For the post-hoc setting, Kuleshov, Fenner, and Ermon (2018) point out that deep regression models' quantiles can be calibrated with binary calibrators such as isotonic regression and yield better performance on downstream tasks such as reinforcement learning. Chung, Neiswanger, Char, and Schneider (2021) introduce some modified loss functions to train quantile calibrators with specific emphases, such as balancing between calibration and sharpness. Regarding the definition of calibration, Song, Diethe, Kull, and Flach (2019) propose a stronger notion of calibration in regression, where the local conditional distribution is required to be calibrated instead of the global quantile. The authors show that being distribution-calibrated in this sense implies being quantile-calibrated. A post-hoc approach based on the Gaussian process is also introduced, where the GP models a distribution of Beta calibrators conditioning on the original regression outputs. Kuleshov and Deshpande (2022) consider achieving post-hoc distribution calibration by learning a lower dimensional representation of the (uncalibrated) local distributions, and the post-hoc calibrators can then be built with density estimators on these representations and the target values, which avoids the costs of distributional kernels and sparse variational inference. Sahoo, Zhao, Chen, and Ermon (2021) propose the definition of threshold calibration for regression models, which is a stronger notion of calibration than being quantile-calibrated and weaker than the distributioncalibrated definition. Instead of asking for calibration on a marginal quantile or local distribution level, the proposed definition requires the model to be calibrated on a group of distributions that satisfy a given threshold condition, which ensures optimal decision-making when a threshold is put on the regression outputs.
Calibration of structured outputs, such as sequential outputs, is also of interest for application domains such as natural language processing and time-series modelling. Kuleshov and Liang (2015) propose approaches to simplify the structured output to a two-class problem and employ a well-calibrated binary classifier to improve the calibration level. On the information-retrieval side, the traditional precision-recall curve is not sufficiently similar to a ROC curve to allow a similar calibration property. In contrast, the precision-recall-gain curve proposed by P.A. Flach and Kull (2015) can be seen as a proper generalisation of ROC curve obtained by replacing weighted accuracy with F-score.
Conformal prediction (Angelopoulos & Bates, 2021;Romano, Patterson, & Candes, 2019;Vovk, Gammerman, & Shafer, 2005) is another area closely related to the topic of probability calibration. For classification, conformal prediction aims to predict a set of labels that has a probability of 1 − α that includes the true label, where α is a user-defined significance level. Therefore, we can see the conformal prediction for classifiers as an alternative definition of calibration to label probability calibration. That is, instead of requiring the probability to be accurate on the label distributions, conformal prediction wants to ensure the calibration on a variable set of labels that are exactly calibrated on the given significance level. One of the approaches to construct a conformal classifier is to use a Venn predictor (Johansson et al., 2018;Vovk & Petej, 2012;Vovk, Shafer, & Nouretdinov, 2003). The framework makes use of the Venn taxonomy to define subsets of the original label space, and requires a classifier to make predictions about each element in the subset. The final conformal prediction can then be calculated using these predictions.

Methods designed for other research fields and applications
The notion of calibration can also be generalised to other areas where uncertainty quantification is of interest. rRecent work has started to explore other topics in statistics, machine learning and artificial intelligence related to calibration. Here we briefly introduce some of them. A comprehensive analysis of these works is left as future work. Pleiss, Raghavan, Wu, Kleinberg, and Weinberger (2017) draw a link between the level of calibration and the evaluation of classifier fairness. Cobb, Roberts, and Gal (2018) propose an approach to modify the lower bound of approximate Bayesian inference so that the final objective function can be calibrated according to a given decision loss. S. Liu, Long, Wang, and Jordan (2018) adopt calibrated deep models to improve zero-shot learning. Menon and Williamson (2018) consider the calibration problem for an anomaly detection setup. Ghandeharioun, Eoff, Jou, and Picard (2019) consider uncertainty and calibration as a tool to improve explainability for computer vision tasks. And J.Z. Liu, Paisley, Kioumourtzoglou, and Coull (2019) adopt a calibration procedure to achieve better posterior distributions for a Bayesian non-parametric ensemble model. Ding, Han, Liu, and Niethammer (2021) consider the problem of improving calibration for semantic segmentation. Guillory, Shankar, Ebrahimi, Darrell, and Schmidt (2021) ;Jiang, Nagarajan, Baek, and Kolter (2021) show that calibrated classifier can be used to estimate the model performance on OOD test sets.

Hypothesis tests for calibration
Even if a classifier is perfectly calibrated, it almost always slightly deviates from calibration on any finite dataset due to sampling effects. Here we consider a method of testing whether the dataset provides sufficient evidence that the classifier is uncalibrated.
A common way to test for calibration is to apply goodness-of-fit tests that were originally proposed for logistic regression models, but can be extended to any model that predicts probabilities. For example, one could apply the Pearson chi-squared goodness-of-fit test, which works by grouping instances sharing the same value of the independent variable X and then applying a chi-squared test under the null hypothesis that the observed number of positives in the target variable is equal to the predicted number of positives for each unique value of X.
The issue with this approach is that the higher the number of unique values of X or the higher the number of combinations of values of multiple independent variables, the lower the probability that each group of instances will be well-represented enough for the calculation of the Pearson chi-squared statistic to be reliable. A possible solution to this problem is to group instances into M bins based on percentiles of the predicted probabilities for the positive class (equal-frequency binning) and then apply the Hosmer-Lemeshow (HL) test, which involves calculating the statistic H given by Equation (20) (Hosmer & Lemeshow, 2003).
where O m+ and O m− are the observed counts of positives and negatives in bin B m and E m+ and E m− are the expected counts of positives and negatives in bin B m , calculated as the sums of positive and negative probabilities in the bin, respectively.
The HL test was later extended to evaluate the goodness-of-fit of multinomial logistic regression models, by binning instances based on the percentiles of ∑ K j=2 s i j = 1 − s i1 , i.e. the complement of the probabilities assigned to the reference class (Fagerland, Hosmer, & Bofin, 2008). Then, similarly to the binary case, once the instances are binned, we calculate O m j and E m j , respectively the observed and expected counts for each class j and bin m. Finally we calculate the C statistic, given by Equation (21), which is expected to follow a chi-squared distribution with (M − 2)(K − 1) degrees of freedom. Table 8 shows M = 5 bins based on the toy example of Table 3. By applying Equation (21) to these values, we get C = 25.3. Finally, to complete the HL test under the null hypothesis that the observed and expected proportions are the same, we compare C to a chi-squared distribution with (M − 2)(K − 1) = 6 degrees of freedom, obtaining a p-value of 0.0003, rejecting the null hypothesis with α = 0.05.  Table 8: Instances grouped into 5 bins using equal-frequency binning on the complement of the probabilities predicted for class 1. Column s(B m ) shows the probability intervals corresponding to each bin. The probabilities were obtained by considering the multiclass toy problem in Table 3.
This example is of course simply illustrative, as the HL test is not recommended for such small samples, as experiments have shown that it has satisfactory power for samples of over 400 instances (Fagerland et al., 2008). There are several other goodness-of-fit tests, most of them using some sort of binning to calculate a statistic that is assumed to follow a chi-squared distribution. Additionally, as the multiclass HL test, they usually test for classwise calibration. Testing for multiclass calibration is a more complex task and has recently been investigated by , by using kernel-based measures. These measures were later adapted for regression calibration (Widmann, Lindsten, & Zachariah, 2022). For details on how these measures can be interpreted as test statistics, we refer the reader to their original papers.
Another approach, proposed by Vaicenavicius et al. (2019), is to test the classifier's probabilities according to an arbitrary measure of calibration. Given a classifier f, we can check if its predictions for a test set {(x 1 , y 1 ), . . . , (x N , y N )} are calibrated according to a chosen calibration measure φ (f(X test ),Ẏ test ), such as ECE, log-loss or Brier score. We discuss a simple resampling-based hypothesis test under the null hypothesis that the classifier's outputs are calibrated (Vaicenavicius et al., 2019). Algorithm 1 details the steps of the hypothesis test procedure.

3:
φ s ← φ f(X test ),Ẏ l ; 4: end for 5: p-value ← proportion of φ l among φ 1 , . . . , φ L with φ l > φ f(X test ),Ẏ test ; 6: if p-value < α then 7: Reject the null hypothesis and conclude that the classifier is not calibrated; 8: else 9: Accept the null hypothesis, i.e. there is not enough evidence that the classifier is not calibrated. 10: end if Let us return to our toy example (Table 3). If we follow Algorithm 1 and choose ECE classwise as the calibration measure and L = 1, 000, we obtain a distribution such as the one in Figure 21.
Recall that in our example ECE classwise = 0.1787. The p-value for this test is then P φ l > 0.1787 ≈ 0.016, which means we can reject the null hypothesis that the classifier is calibrated according to ECE classwise . Note that we keep the scores fixed and only resample the labels to perform this test. This means that instances will stay in the same bins and small bins will have low weights for all L resampled ECE classwise values.

Concluding remarks
In this survey we have given a detailed overview of the principles and practice of classifier calibration. We discussed the motivation, definition, evaluation and related approaches for the calibration of probabilistic classifiers, and touched upon topics beyond the standard classification setting. With the recent proliferation of predictive machine learning, it is becoming more and more important that models are carefully evaluated and if possibly improved on multiple criteria to ensure the overall system robustness. Classifier calibration relates to the criterion of uncertainty quantification, investigating the statistical relationships between model predictions and observed target variables. There are other levels of uncertainty in the overall modelling procedure, including uncertainty pertaining to model parameters when the training set is limited, uncertainty brought about by model mismatch, or uncertainty regarding whether the model should abstain when there might be novel target values that were not seen in the training set -see (Hüllermeier & Waegeman, 2021) for a recent survey on uncertainty in machine learning.
As we hopefully have made clear in this survey, calibration research has a rich history which predates the birth of machine learning as an academic field by decades. It is important to take full advantage of that history, which perhaps isn't always fully acknowledged in recent literature on classifier calibration (e.g., of deep neural networks, which are often over-confident). Recent proposals such as confidence calibration, temperature scaling and expected calibration error have value but are far from the only options and may not be suitable for a particular application. As is often the case in machine learning, the space of options and things to consider is large, and navigating this space requires the right set of concepts and tools, many of which we have discussed in detail in this survey.
It is perhaps useful to point out that, naturally, there are also concepts that are less than helpful when thinking about classifier calibration. One of the most prominent of these is the concept of a decision boundary, which is like describing Mount Everest with a single contour line, halfway up. To faithfully characterise the mountain -which is what is needed for optimal decision making -one needs many contour lines at different elevations. The only case in which the decision boundary is useful is when the class prior (and misclassification costs, if any) won't change after training, in which case only the decision threshold needs calibrating. In all other cases context change is expected and needs to be anticipated with a proper calibration analysis.
If a trained classifier f is going to be used for a task for which it is good enough to be accurate, precise or to perform well according to any contingency matrix-based measure, then there is no particular need to consider calibration in the model's development pipeline. However, if calibrated probabilities are important for any decisions supported by f , the following steps can be taken to implement what was discussed in this paper: 1. If possible, any classifiers considered for a task should be trained using a proper scoring rule as loss function; • The resulting models are likely to produce better probabilities than if a nonproper loss function is used, as probability refinement and calibration will be encouraged during training (recall Section 3); • An alternative is to use a method that encourages calibration during training time, as discussed in Section 5.6; 2. With the trained classifiers and, preferably a held-out calibration dataset, the calibration of the probabilities produced by the models can be evaluated using classwise reliability diagrams, to understand the miscalibration patterns, and/or ECE measures (recall Section 4); 3. To help define which models are uncalibrated, a hypothesis test for calibration can be applied (recall Section 6); 4. If any models produce uncalibrated probabilities, post-hoc calibrators should be used to fix them; • The resulting calibrators should also be evaluated using reliability diagrams, ECE measures and hypothesis tests to find out which ones work best for the particular miscalibration patterns found during step 2.
In order to help with the aforementioned steps, we have developed an open-source Python library called PyCalib (Perello-Nieto, Song, Silva Filho, & Kängsepp, 2021) 4 . This library provides tools to measure the calibration quality of a classifier, multiple visualisation functions to better understand how calibrated is a model, and some calibration methods and pipelines to directly train arbitrary calibrated classifiers.
We close this survey with some open problems. First, although binning is such an important concept in calibration, there is no standard method to decide which type of binning, e.g. equal frequency or equal width, or what number of bins to use. Recent work (Kängsepp, Valk, & Kull, 2022) has investigated cross-validation to tune the number of bins used to evaluate a model on a calibration set. Second, a recurrent topic of interest is the fact that post-hoc calibration does not improve robustness against out-of-distribution inputs and what can be done to improve calibration in this context (Ovadia et al., 2019). Finally, and somewhat related to the previous point, even though calibrated probabilities provide estimations of the uncertainty regarding an instance's class given its feature values (aleatoric or first-order uncertainty), classifiers could also be made to predict their uncertainty about the predicted probabilities, which comes from not knowing the true probabilities (epistemic uncertainty). This type of prediction, a distribution of distributions, also called second-order uncertainty (Bengs, Hüllermeier, & Waegeman, 2022;Hüllermeier, Destercke, & Shaker, 2022), has been recently treated using inference based on Bayesian methods and credal sets, which are convex sets of probability distributions (Shaker & Hüllermeier, 2021).

Funding
The work of PF, RSR and MPN was supported by the SPHERE Next Steps Project funded by the UK Engineering and Physical Sciences Research Council (EPSRC)