On Calibration and Out-of-domain Generalization
Year: 2021

Abstract:
Out-of-domain (OOD) generalization is a significant challenge for machine learning models. Many techniques have been proposed to overcome this challenge, often focused on learning models with certain invariance properties. In this work, we draw a link between OOD performance and model calibration, arguing that calibration across multiple domains can be viewed as a special case of an invariant representation leading to better OOD generalization. Specifically, we show that under certain conditions, models which achieve multi-domain calibration are provably free of spurious correlations. This leads us to propose multi-domain calibration as a measurable and trainable surrogate for the OOD performance of a classifier. We therefore introduce methods that are easy to apply and allow practitioners to improve multi-domain calibration by training or modifying an existing model, leading to better performance on unseen domains. Using four datasets from the recently proposed WILDS OOD benchmark [23], as well as the Colored MNIST dataset [21], we demonstrate that training or tuning models so they are calibrated across multiple domains leads to significantly improved performance on unseen test domains. We believe this intriguing connection between calibration and OOD generalization is promising from both a practical and theoretical point of view.

heading: 1 Introduction
text: Machine learning models have recently displayed impressive success in a plethora of fields [19, 9, 41]. However, as models are typically only trained and tested on in-domain (ID) data, they often fail to generalize to out-of-domain (OOD) data [23]. The problem is especially pressing when deploying machine learning models in the wild, where they are required to perform well under conditions that were not observed during training. For instance, a medical diagnosis system trained on patient data from a few hospitals could fail when deployed in a new hospital.
Many methods have been proposed to improve the OOD generalization of machine learning models. Specifically, there is rapidly growing interest in learning models that display certain invariance properties under distribution shifts and do not rely on spurious correlations in the training data [34, 17, 1]. While highlighting the need for learning robust models, so far these attempts have limited success scaling to realistic high-dimensional data, and in learning truly invariant representations [37, 11, 20].
In this paper, we argue that an alternative and relatively simple approach for learning invariant representations could be achieved through model calibration across multiple domains. Calibration asserts that the probabilities of outcomes predicted by a model match their true probabilities. Our claim is that simultaneous calibration over several domains can be used as an observable indicator
⇤Equal contribution
35th Conference on Neural Information Processing Systems (NeurIPS 2021).
for favorable performance on unseen domains. For example, if we take all patients for whom a classifier outputs a probability of 0.9 for being ill, and in one hospital the true probability of illness in these patients is 0.85 while in the other it is 0.95, then we may suspect the classifier relies on spurious correlations. Intuitively, the features which lead the classifier to predict a probability of 0.9 imply different results under different experimental conditions, suggesting that their correlation with the label is potentially unstable. Conversely, if the true probabilities in both hospitals match the classifier’s output, it may be a sign of its robustness.
Our contributions are as follows: We prove that in Gaussian-linear models, under a general-position condition, being concurrently calibrated across a sufficient number of domains guarantees a model has no spurious correlations. We then introduce three methods for encouraging multi-domain calibration in practice. These are, in ascending order of complexity: (i) model selection by a multi-domain calibration score, (ii) robust isotonic regression as a post-processing tool, and (iii) directly optimizing deep nets with a multi-domain calibration objective, based on the method introduced by Kumar et al. [26]. We show that multi-domain calibration achieves the correct invariant classifier in a learning scenario presented by Kamath et al. [20], unlike the objective proposed in Invariant Risk Minimization [1]. Finally, we demonstrate that the proposed approaches lead to significant performance gains on the WILDS benchmark datasets [23], and also succeed on the colored MNIST dataset [21].

heading: 2 Calibration and Invariant Classifiers

heading: 2.1 Problem Setting
text: Consider observable features X , a label Y and an environment (or domain) E with sample spaces X ,Y, E accordingly. We mostly focus on regression and binary classification, therefore Y = R or Y = {0, 1}. To lighten notation, our definitions will be given for the binary classification setting and we will point out adjustments to regression where necessary. There is no explicit limitation on |E|, but we assume that training data that has been collected from a finite subset of the possible environments Etrain ⇢ E . The number of training environments is denoted by k, and Etrain = {ei}ki=1 ⇢ E , so that our training data is sampled from a distribution P [X,Y | E = ei] 8i 2 [k]. Our goal is to learn models that will generalize to new, unseen environments in E .
Ideally, we would like to learn a classifier that is optimal for all environments E . Unfortunately, we only observe data from the limited set Etrain and even if this set is extremely large, the Bayes optimal classifiers on each environment do not necessarily coincide. Following other recent work [34, 17, 1] we therefore aim for a different goal – learning classifiers whose per-instance output will be stable across environments E, as we explain below.
We assume the data generating process for E,X, Y follows the causal graph in Figure 1. 2 We differentiate between causal and anti-causal components of X , and further differentiate between the anti-causal variables which are affected or unaffected by E, denoted as Xac-spurious and Xac-non-spurious, respectively. As an illustrative example, consider again predicting illness across different hospitals. When predicting lung cancer, Y , from patient health records, Xcausal could be features like smoking. Xac-non-spurious are symptoms of Y such as infections that appear in chest X-rays, while Xac-spurious can be marks that technicians put on X-rays as in [51]. Smoking habits may vary across hospital populations, as might X-ray markings; but the influence of smoking on cancer and the manifestation of cancer in an X-ray do not vary by hospital.
We do not assume to know how to partition X into Xcausal, Xac-spurious, Xac-non-spurious. The main assumptions made in the causal graph in Fig. 1 are that there are no hidden variables, and that there is no edge directly from environment E to the label Y . Such an arrow would imply the conditional distribution of Y given X can be arbitrarily different in an unseen environment E, compared to those present in the training set. Note that for simplicity we do not include arrows from Xcausal to Xac-spurious and Xac-non-spurious but they may be included as well.
2See Appendix A.3 for a brief introduction to causal graphs.
We will say a representation (X) contains a spurious correlation with respect to the environments E and label Y , if Y ?6 E | (X); this motivates our naming of Xac-spurious and Xac-non-spurious in Fig. 1, as Y ?6 E | Xac-spurious but Y ? E | Xac-non-spurious. Similar observations have been made by [17, 1]. Having a spurious correlation implies that the relation between (X) and Y depends on the environment – it is not transferable nor stable across environments. In this work we will simply consider the output f(X) of a classifier f : X ! [0, 1] as a representation. The crux of this paper is the observation that having E[Y | f(X), E = e] = f(X) for every value of E, i.e. f being a calibrated classifier across all environments, is equivalent up-to a simple transformation to having Y ? E | f(X), and thus to f having no spurious correlations with respect to E. We prove this assertion in section 2.2, and as a demonstration of this principle we prove (section 3) that linear models which are calibrated across a diverse set of environments E are guaranteed to discard Xac-spurious as viable features for prediction.

heading: 2.2 Invariance and Calibration on Multiple Domains
text: We define calibration, along with a straightforward generalization to the multiple environment setting. Definition 1. Let P [X,Y ] be a joint distribution over the features and label, and f : X ! [0, 1] a classifier. Then f(x) is calibrated w.r.t to P if for all ↵ 2 [0, 1] in the range of f , EP [Y | f(X) = ↵] = ↵. In the multiple environments setting, f(x) is calibrated on Etrain if for all ei 2 Etrain and ↵ in the range of f restricted to ei, E[Y | f(X) = ↵, E = ei] = ↵.
For regression problems, we consider regressors that output estimates for the mean and variance of Y , and say they are calibrated if they match the true values similarly to the definition above. The precise definition can be found in the supplementary material.
We now tie the notion of calibration on multiple environments with OOD generalization, starting with its correspondence with our definition of spurious correlations. Recall that a representation (X) does not contain spurious correlations if Y ? E | (X). Treating the output f(X) of a classifier as a representation of the data, and considering classifiers satisfying the above conditional independence with respect to training environments, we arrive at a definition of an invariant classifier. Definition 2. Let f : X ! [0, 1]. f is an invariant classifier w.r.t Etrain if for all ↵ 2 [0, 1] and environments ei, ej 2 Etrain, where ↵ is in the range of f restricted to each of them:
E[Y | f(X) = ↵, E = ei] = E[Y | f(X) = ↵, E = ej ]. (1)
Lemma 1 gives the correspondence between invariant classifiers and classifiers calibrated on multiple environments. The proof is in Section A.1 of the supplementary material. Lemma 1. If a binary classifier f is invariant w.r.t Etrain, then there exists some g : R! [0, 1] such that (i) g f is calibrated on all training environments, and (ii) the mean squared error of g f on each environment does not exceed that of f . On the other hand, if a classifier is calibrated on all training environments it is also invariant w.r.t Etrain.
Now, we can note how the above notion of invariance relates to that of Invariant Risk Minimization [1], where invariance of a representation : X ! H is linked to a shared classifier w⇤ : H! [0, 1], w⇤ being optimal on all environments w.r.t a loss l : [0, 1]⇥Y ! R 0. Under the representation (X) = f(X), and the cross-entropy or squared losses it turns out that the original IRM definition coincides with Equation (1) 3. Hence we aim for a similar notion of conditional independence, yet we approach it from the point-of-view of calibration. In Section 5 we will see that taking this approach leads to different methods that are highly effective in achieving and assessing invariance. We further note that the original IRM objective was deemed too difficult to optimize by the original IRM authors, leading them to propose an alternative called IRMv1. This alternative however does not capture the full set of required invariances, as shown by [20], whereas we show in section 6.1 that multi-domain calibration does indeed capture the required invariances.
Having established the connection between calibration on multiple environments and invariance, there are several interesting questions and points to consider: Calibration and sharpness. Calibration alone is not enough to guarantee that a classifier performs well; on a single environment, always predicting E[Y ] will give a perfectly calibrated classifier.
3See Observation 2 in [20] for a proof.
Hence, multi-domain calibration should be combined with some sort of guarantee on accuracy. In the calibration literature, this is often referred to as sharpness. To this end, in Section 5 we will propose regularizing models during training or fine-tuning with Calibration Loss Over Environments (CLOvE). Combining this regularizer with standard empirical loss functions helps balance between sharpness and multi-domain calibration. Even without training a new model, we will propose methods for model selection and post-processing that are very easy to apply and help improve multi-domain calibration without a significant effect on the sharpness of the models. Generalization and dependence on Xac-spurious. Suppose that f(X) is calibrated on Etrain. Under what conditions does this imply it is calibrated on E? It is easy to show that calibration on several environments entails calibration on any distribution which can be expressed as a linear combination of the distributions underlying said environments. However, can we go beyond that? Given a general set E we would like to know what conditions and how many training environments are required for calibration to generalize. We also wish to understand when does calibration over a finite set of training environments indeed guarantee that a classifier is free of spurious correlations. We now turn to answer these questions in the setting of linear-Gaussian models.

heading: 3 Motivation: a Linear-Gaussian Model
text: Let us consider data where X is a multivariate Gaussian. Since we will be considering Gaussian data, the set of all environments E will be parameterized using pairs of real vectors expressing expectations and positive definite matrices of an appropriate dimension expressing covariances: E = {(µ,⌃) | µ 2 Rd,⌃ 2 Sd++}. For two scenarios ((a) and (b) in Figure 2) we prove that when provided with data from k training environments, where k is linear in the number of features, and the environments satisfy some mild non-degeneracy conditions, any predictor that is calibrated on all training environments will not rely on any of the spurious features Xac-sp, and will also be calibrated on all e 2 E .
In scenario (a), we take Y to be a binary variable drawn from a Bernoulli distribution with parameter ⌘ 2 [0, 1], and observed features are generated conditionally on Y . The features xac-ns 2 Rdns are invariant, meaning their conditional distribution given Y is the same for all environments, whereas xac-sp 2 Rdsp are spurious features, as their distribution may shift between environments, altering their correlation with Y . The data generating process for training environment i 2 [k] in Fig. 2(a) is given by:
y = ⇢ 1 w.p ⌘ 0 o.w
Xac-ns | Y = y ⇠ N ((y 1/2)µns,⌃ns) ,
Xac-sp | Y = y ⇠ N ((y 1/2)µi,⌃i) . (2)
For x = [xac-ns,xac-sp] we consider a linear classifier f(x;w, b) = (w>x+b), where : R! [0, 1] is some invertible function (e.g. a sigmoid). Since the mean of spurious features, µi, is determined by y, these features can help predict the label in some environments. Yet, these correlations do not carry to all environments, and f(x) might rely on spurious correlations whenever the coefficients in w corresponding to xac-sp are non-zero. Any such classifier can suffer an arbitrarily high loss in an unseen environment, because a new environment can reverse and magnify the correlations observed in Etrain. Using these definitions, we may now state our result for this case: Theorem 1. Given k > 2dsp training environments where data is generated according to Equation (2) with parameters {µi,⌃i}ki=1, we say they lie in general position if for all non-zero x 2 Rdsp :
dim span
⇢ ⌃ix+ µi
1
i2[k]
! = dsp + 1.

heading: If a linear classifier is calibrated on k training environments which lie in general position, then its
text: coefficients for the features xac-sp are zero. Moreover, the set of training environments that do not lie in general position has measure zero in the set of all possible training environments Ek.
As a corollary, we see that calibration on training environments generalizes to calibration on E . The proof of this theorem is given in the supplementary material, Section A.4. The data generating process closely resembles the one considered by [37], who use diagonal covariance matrices.
In the second scenario we consider the addition of causal features subject to covariate shift xc 2 Rdc , as shown in Figure 2b. The covariate shift is induced when the environments E alter the distribution of the causal features xc [40]. In this case, we analyze a regression problem since it is amenable to exact analysis. The data generating process for training environment i 2 [k] is:
Xc ⇠ N (µ c i ,⌃ c i ); Y = w ⇤ c >xc + ⇠, ⇠ ⇠ N (0, 2 y)
Xac-sp = yµi + ⌘, ⌘ ⇠ N (0,⌃i). (3) For x = [xc,xac-sp] it turns out that in this case, calibration on multiple domains forces f(x) to discard xac-sp, but also forces it to use w⇤c , since it characterizes P (Y | xc) which is the invariant mechanism in this scenario. The exact statement and proof are in Section A.5 of the supplement. Theorem 2 (informal). Let f(x;w) = w>x be a linear regressor and assume we have k > max {dc + 2, dsp} training environments where data is generated according to Equation (3). Under mild non-degeneracy conditions, if the regressor is calibrated across all training environments then the coefficients corresponding to Xc equal w⇤c and those that correspond to Xac-sp are zero.
Together, these results show calibration can generalize across environments, given that the number of environments is approximately that of the spurious features. They also show that for the settings above, the relatively stable and well-known notion of calibration implies avoiding spurious correlations.

heading: 4 Related Work
text: As discussed in Section 2, multi-domain calibration is an instance of an invariant representation [1]. Many extensions to the above work have been proposed, e.g. [24, 3]. Yet, recent work claims that many of these approaches still fail to find invariant relations in cases of interest [20, 37, 13], where a significant challenge seems to be the gap between what is achieved by the regularization term used in practice and the goal of conditional independence Y ? E | (X). Gulrajani et al. [11] give a sobering view on methods for OOD generalization, emphasizing the power of ERM and data augmentation, and the challenge of model selection. We claim that compared to the above approaches, multi-domain calibration studied here is a simpler form of invariance. Furthermore, calibration is attractive because there are standard tools to quantify it such as calibration scores [31] and a vast literature on its properties and how it can be obtained [50, 47, 30, 26, 45, 14, 36].
Learning models which generalize OOD is a fruitful area of research with many recent developments. Most work focuses on the case of Domain Adaptation where unlabeled samples are available from the target domain, including recent work on OOD calibration [48]. However, important work has also been done on the area of our focus – the so-called “proactive” case [43], where no OOD samples are available whatsoever [28, 17, 38, 34, 39].
Calibration also plays an important role in uncertainty estimation for deep networks [12], and recently in fairness, where calibration on subgroups of populations is sought [35]. This has interesting resemblance to the multiple environments calibration we consider here. A more general notion of multi-calibration has also been studied in this context [16], with recent results on sample complexity [42] which may provide tools to finite sample analysis of domain generalization. Finally, multiple methods for training calibrated models [26, 29, 36] have also been proposed. In Section 5 we propose a generalization of [26] to the multi-domain case to achieve multi-domain calibration.

heading: 5 Proactively Achieving Multi-Domain Calibration
text: So far we have seen a general argument why calibration can limit spurious correlations, and that in linear-Gaussian models multi-domain calibration guarantees OOD generalization. Now we turn to a more applied perspective and show how can we optimize models so they achieve this type of calibration in practice. We propose three approaches: (1) using calibration measures for model selection, (2) post-processing calibration, and (3) a calibration objective building on a method proposed by [26]. Section A.1 in the supplementary provides a slightly broader introduction to notions we use here. We will assess model calibration by the Expected Calibration Error (ECE) of the calibration curve [7], which is the average deviation between model accuracy and model confidence.

heading: 5.1 Model selection with average ECE
text: Model selection is challenging when aimed at OOD generalization. As recently observed by [11], since OOD accuracy is often at odds with In-Domain (ID) accuracy, selection based on ID validation error eliminates the advantage of domain generalization methods over vanilla ERM with data augmentation. We suggest that model selection towards OOD generalization should balance ID validation error with another observable surrogate for the stability of a model to distribution shifts between domains. Motivated by multi-domain calibration, we propose using the average ECE across training environments as this surrogate. Concretely, we propose choosing a model with lowest average ECE from those obtaining ID validation accuracy that is above a certain user-defined threshold.

heading: 5.2 Post-Processing Calibration
text: Practitioners interested in (single-domain) calibrated models often apply post-processing calibration methods to binary classifiers, where the most widely used approach is Isotonic Regression Scaling [50, 30]. Unlike standard calibration problems, in our case there are multiple domains to calibrate over. We give two ways of extending Isotonic Regression to the multi-domain setting, which we term “naive calibration” and “robust calibration”. Naive Calibration takes predictions of a trained model f on validation data pooled from all domains and fits an isotonic regression z⇤. We then report the performance of z⇤ f on the OOD test set. Robust Calibration: In a multiple domain setting, Naive calibration may produce a model that is well calibrated on the pooled data, but uncalibrated on individual environments. Since our goal is simultaneous calibration, the following alternative attempts to bound the worst-case miscalibration across training environments. For each environment e 2 Etrain, we denote the number of validation examples we have from it by Ne, and by fe,i the prediction of the model on the i-th example. Then in a similar vein to robust optimization, we fit an isotonic regressor that
solves: z⇤ = argmin z max e2Etrain
1
Ne
NeX
i=1
(z(fe,i) yi) 2. Since Isotonic Regression can be formulated as
a quadratic program, and Equation (5.2) minimizes a pointwise maximum over such objectives, we can cast Eq. 5.2 as a convex program and solve with standard optimizers. We then evaluate the OOD performance of z⇤ f .

heading: 5.3 Learning with Multi-Domain Calibration Error
text: The above model selection and post-processing methods are easy to apply and (as we will soon see) surprisingly effective. However, both are limited in their power to learn a model that is truly well-calibrated across multiple domains. We now propose a more powerful approach: an objective function that directly penalizes calibration errors on multiple domains during training. Specifically, we propose learning a parameterized classifier f✓(x) using a learning rule of the form: min✓ P e2Etrain
le(f✓) + · r(f✓), where l : R ⇥ R ! R is an empirical loss function (e.g. crossentropy) and le(f✓) denotes the expected loss over data from training environment e, and r(f✓) is a regularization term over multiple environments. Using this notation the method proposed by [1] learns a classifier f = w with a regularizer given by r(f) =
P e2Etrain
reIRMv1(f), where reIRMv1(f) = krw|w=1l e(w · )k2.
Our proposed regularizer r(f✓) is based on the work of Kumar et al. [26], who introduce a method they call Maximum Mean Calibration Error (MMCE). MMCE harnesses the power of universal kernels to express the ECE as an Integral Probability Measure, and works as follows: For a dataset D = {xi, yi}mi=1, denote the confidence of a classifier on the i-th example by f✓;i = max{f✓(xi), 1 f✓(xi)} and its correctness by ci = |yi f✓;i|< 12 . For a given universal kernel k : R ⇥ R ! R, MMCE over the dataset D is given by: rDMMCE(f✓) = 1 m2 P
i,j2D (ci f✓;i)(cj f✓;j)k(f✓;i, f✓;j). Calibration Loss Over Environments (CLOvE). Given multiple training domains with a dataset De for each e 2 Etrain, we arrive at our proposed regularizer by aggregating MMCE over them: rCLOvE(f✓) = P e2Etrain
rDeMMCE(f✓). A key property of CLOvE is that its minima correspond to perfectly calibrated classifiers over all training domains, a consequence of the correspondence between MMCE and perfect calibration. Corollary 1 (of Thm. 1 in [26]). CLOvE is a proper scoring rule. That is, it equals 0 if and only if f✓(x) is perfectly calibrated for every e 2 Etrain.
Additional properties of CLOvE, such as large deviation bounds and relation to ECE, can also be derived; see results in [26] for further details. In the following section, we will see how these properties translate into favorable OOD generalization in practice when training with CLOvE.

heading: 6 Experiments and Results

heading: 6.1 Colored MNIST and Two-Bit Environments
text: In order to explore the challenges of OOD generalization and how they relate to learning from multiple environments, [1] used the colored MNIST dataset [21]. In this dataset certain digits tend to be colored either red or green in the train set, but the correlation between colors and digits is flipped in the OOD test set, making color a spurious feature. This dataset was then further simplified into “Two-Bit” environments by [20], who proved that the IRMv1 penalty proposed in [1] does not in fact achieve the correct invariant solution on the simplified setting. The Two-Bit environments problem setting has two binary features, X1, X2 2 { 1, 1}, corresponding respectively to digit identity (0 4 or 5 9) and digit color in the original colored MNIST. The environments are parameterized by e = (↵, ) 2 [0, 1]2 controlling the correlation of the features with the label: Y Rad(0.5), X1 Y · Rad(↵), X2 Y · Rad( ), where Rad( ) is a random variable equal to 1 with probability and 1 with probability 1 . At training we are given data from two environments e1 = (↵, 1), e2 = (↵, 2), 1 6= 2. The learned model is tested on a new environment e3 = (↵, 3) with 3 significantly different from 1, 2. Only a model discarding the spurious feature X2 will maintain its accuracy moving from train to OOD test. Calibration discards spurious correlation in Two-Bit environments. Figure 3(a), which we adapt from Figure 6 in Appendix B of [20], illustrates the merits of CLOvE in this setting. The figure shows the space of odd classifiers, i.e. those for which f(1, 1) = f( 1, 1), and f(1, 1) = f( 1, 1).4 The true invariant classifiers are those for which in addition f(1, 1) = f(1, 1), corresponding to models lying on the diagonal of Figure 3(a), denoted by the dashed gray line. In the figure, we plot in solid lines the classifiers for which reIRMv1(f) equals 0, and in solid circles the classifiers for which reMMCE(f) equals 0 (due to Corollary 1 these coincide with calibrated classifiers on environment e). Note that in this parameterization, the zeros of reIRMv1(f) are lines whereas the zeros of r e MMCE(f) are isolated points. Intersections of the zeros of reIRMv1(f) denote solutions for which the corresponding regularization terms are 0 on all respective environments, while intersection of zeros of reMMCE(f) are the zeros of rCLOvE(f). As observed by [20], when Etrain = {e1, e2} the solution denoted by OPTIRMv1 has the lowest empirical loss, yet this solution has a spurious correlation with X2 and thus will incur a higher loss on the test environment e3. This means the corresponding IRMv1 learning rule cannot retrieve the optimal invariant classifier. On the other hand, learning with CLOvE does retrieve the optimal invariant classifier in this case, in addition to the trivial, constant classifier. This means CLOvE discards spurious correlations in cases where IRMv1 does not. In Section C we present experiments reproducing the above scenario on the Colored MNIST dataset.
Model selection based on average ECE We train models with varying hyperparameters on Colored MNIST using ERM, CLOvE and IRM, (100 models with each algorithm, see Section C of the supplement for details). We then calculate the ECE and IRMv1 penalties of each model over a held-out validation set from each training environment, and evaluate the average of these against OOD accuracy. Figure 3(b) presents the results across all trained models. The ID ECE penalty displays a very strong correlation across the entire range and every training regime (Pearson corr. = -0.92), while ID IRMv1 behaves more erratically (Pearson corr. = -0.59). Since quantities used for model selection should be agnostic to choices made at training time, we suggest that ID ECE is a better choice for use in model selection. Further results on model selection can be found in the supplement, Section C.

heading: 6.2 WILDS Benchmarks
text: WILDS is a recently proposed benchmark of in-the-wild distribution shifts from several data modalities and applications5. Table 1 presents the four WILDS datasets we experiment with, chosen to represent diverse OOD generalization scenarios. We follow the models and training algorithms
4As explained in [20], the optimal solutions are odd so we may focus on them for visualization purposes. 5https://wilds.stanford.edu
proposed by [23]. In order to perform multi-domain calibration we modify the splits to include a multi-domain validation set whenever possible. See supplemental Section B for details and for additional results on Amazon Reviews. As in [23], we use three different training algorithms to train our models: ERM, IRM, DeepCORAL, and further use GroupDRO for one of the datasets, compatible with WILDS version 1.0.0. We apply three calibration approaches described in 5.2 and 5.3 above to each trained model: naive calibration and robust calibration, which are post-processing methods and therefore applied on the models’ outputs; and CLOvE, which we apply as a fine-tuning approach to the top layers of each trained model. We train each (algorithm⇥ calibration) combination four times with different random seeds, and report average results and their standard deviations.
Table 2 presents our main results on the FMoW (left) and Camelyon17 (right) datasets. On both datasets, robust calibration already improves performance, and CLOvE then significantly outperforms robust calibration, improving performance by 7% and 2.8% (absolute) over the strongest alternative on FMoW and Camelyon17, respectively. When compared to the original model, the performance of CLOvE is even more striking, with CLOvE outperforming it by more than 10% (absolute) on FMoW and 6% on Camelyon17. Another appealing property of CLOvE is the low variance exhibited across different runs. Indeed, CLOvE has lower variance than both naive and robust calibration approaches, and has lower variance than the original (uncalibrated) model on 4 of the 6 experiments.
Analysis. As can be seen in Figure 4, improvements in ID calibration are associated with better OOD performance. Interestingly, when our post-processing does not improve OOD performance, it
is often linked to our inability to substantially improve ID calibration. This is most visible in IRM experiments, where robust calibration is unable to outperform naive calibration both in terms ID calibration and in OOD performance. Finally, we find it interesting that merely post-processing the data (as in robust calibration) can already have such a marked effect on OOD accuracy, though still inferior to actually optimizing for multi-domain calibration as done by CLOvE.
Results on alternative settings. While our theoretical analysis is focused on OOD generalization of classification models, we also experiment with alternative settings from WILDS to test the power of ID calibration in improving OOD performance. Specifically, we experiment with the PovertyMap dataset, which introduces a regression task, and the CivilComments dataset, which introduces a subpopulation shift scenario for a binary classifier. As can be seen in Table 3, results on the CivilComments dataset (right), show that calibration consistently improves worstcase performance, with an average improvement of 21.5% across training algorithms. While CLOvE does outperform naive and robust calibration on average, the gain is lower in comparison to FMoW and Camelyon17.
In PovertyMap (left), the model solves a regression task, so we cannot use CLOvE to improve OOD performance. Still, robust calibration improves performance across all experiments, though by a smaller margin. In the case of models pre-trained by IRM, robust calibration improves OOD performance substantially, outperforming the original model by 0.08% (absolute). Interestingly, calibration also leads to more stable results both in PovertyMap and in CivilComments, as can be seen in the standard deviation across different model runs.

heading: 7 Conclusion
text: In this paper we highlight a novel connection between multi-domain calibration and OOD generalization, arguing that such calibration can be viewed as an invariant representation. We proved in a linear setting that models calibrated on multiple domains are free of spurious correlations and therefore generalize out of domain. We then proposed multi-domain calibration as a practical and measurable surrogate for the OOD performance of a classifier. We demonstrated that actively tuning models to achieve multi-domain calibration significantly improves model performance on unseen test domains, and that in-domain calibration on a validation set is a useful criterion for model selection. A major limitation of our work is that our theoretical findings are limited to linear models in a population (as opposed to finite-sample) setting; we thus consider them more as a motivation rather than a full justification of using multi-domain calibration in practice as we do. We look forward to expanding the scope of theoretical understanding of the conditions under which multi-domain calibration can provably guarantee out-of-domain generalization, including the finite-sample setting and the analysis of specific algorithms. We also expect new practical methods, building on our findings, will help push forward the real-world ability to generalize to unseen test domains.

heading: Acknowledgments
text: We wish to thank Ira Shavitt for his helpful comments and to Alexandre Ramé for pointing us to an error in the original manuscript. This research was partially supported by the Israel Science Foundation (grant No. 1950/19).

Review summaries:
This work suggests that for well calibrated models will achieve better performance on OOD data. It is shown empirically that expected calibration error (ECE) is negatively correlated with OOD performance, and various methods of selecting calibrated models are suggested. The best performing method involves regulation to encourage calibration during training.

This paper draws an important connection between out-of-domain generalization and calibrated models. Specifically, it is argued that calibrated models are related to invariant representations w.r.t spuriously correlated features, which is necessary for generalization across multiple domains. The paper proves this statement in the case of a multivariate linear-Gaussian model. The authors empirically find a correlation between the Expected Calibration Error (ECE) and OOD performance on Colored MNNIST. Based on these insights, the authors propose three methods for achieving multi-domain calibration of trained models in practice: Approach #1 suggests doing model selection based on the Expected Calibration Error; Approach #2 is intended to augment the trained model by post-processing calibration methods and Approach #3 introduces a calibration objective at train time. In multiple experiments across 5 datasets, reported results suggest that their method outperforms the baselines algorithms without calibration on OOD test environments.  

The paper proposes out-of-domain (OOD) generalization of the machine learning models by calibrating them across multiple domains. The paper argues that multi-domain calibration makes the model learn invariant features and therefore free of spurious correlations. The relationship between calibration and invariance has been clearly stated via lemma. The authors prove how multi-domain calibration makes the model free of spurious correlations in the case of a linear Gaussian model and in two different scenarios. Different ways of practically achieving multi-domain calibration, i.e., during model selection, as post-processing techniques on the trained model, and during training have been proposed. Experimental results on the WILDS OOD benchmark and Colored MNIST dataset illustrate the efficacy of the proposed ways for calibrating a model on multi-domains for OOD generalization.