OOD-Chameleon: Is Algorithm Selection for OOD Generalization Learnable?

## Abstract

Abstract Out-of-distribution (OOD) generalization is challenging because distribution shifts come in many forms.
A multitude of learning algorithms exist and each can improve performance in specific OOD situations.
We posit that much of the challenge of OOD generalization lies in choosing the right algorithm for the right dataset .
However, such algorithm selection is often elusive under complex real-world shifts.
In this work, we formalize the task of algorithm selection for OOD generalization and investigate whether it could be approached by learning. We propose a solution, dubbed OOD-Chameleon that treats the task as a supervised classification over candidate algorithms.
We construct a dataset of datasets to learn from, which represents diverse types, magnitudes and combinations of shifts (covariate shift, label shift, spurious correlations).
We train the model to predict the relative performance of algorithms given a dataset’s characteristics.
This enables a priori selection of the best learning strategy,
i.e. without training various models as needed with traditional model selection. Our experiments show that the adaptive selection outperforms any individual algorithm
and simple selection heuristics,
on unseen datasets of controllable and realistic image data.
Inspecting the model shows that it learns non-trivial data/algorithms interactions,
and reveals the conditions for any one algorithm to surpass another.
This opens new avenues for (1) enhancing OOD generalization with existing algorithms instead of designing new ones, and (2) gaining insights into the applicability of existing algorithms with respect to datasets’ properties.

## 1 Introduction

#### The many faces of OOD generalization.

Out-of-distribution (OOD) generalization refers to a model’s ability to remain accurate when the distributions of the training and test data differ.
“OOD” is a catch-all term since it encompasses many types of distribution shifts (Wiles et al., ; Ye et al., ; Nagarajan et al., ).
In medical imaging for example (Oakden-Rayner et al., ), a model may have to process X-rays from various demographics (*covariate shift*), pathologies (*label shift*), and co-occurrences of patient attributes (*spurious correlations*).
These types of shifts have often been studied independently, and are often best addressed with different algorithms.
However, real data is often complicated by *combinations* of shifts of different types and magnitudes (Wiles et al., ; Yang et al., ) that interact in complex ways with the learning algorithms (Jiang et al., ; Cabannes et al., ; Benoit et al., ).

#### The trade-offs of learning algorithms.

OOD generalization is challenging because it is fundamentally underspecified (D’Amour et al., ; Teney et al., ).
The training set alone is not enough to inform about the nature of the shifts nor to constrain the behavior of the model on OOD test data.
This is why a multitude of learning algorithms exist, which rely on different assumptions or side information (e.g. domain labels), from standard ERM (Vapnik, ) to simple interventions such as Resampling, GroupDRO (Sagawa et al., ), and more-complex ones (Liu et al., ).

Figure: Figure 1: Given a dataset, how can one choose an algorithm such that the most robust model is obtained after training on the dataset? (right) We propose the task of algorithm selection for OOD generalization and build an automated algorithm selector dubbed OOD-Chameleon. We train the model on a dataset of datasets that exemplify a variety of distribution shifts (left) and show that it learns non-trivial data/algorithms interactions for algorithm selection.
Refer to caption: x1.png

A well-known study by Gulrajani & Lopez-Paz () showed that none of these methods surpasses an ERM baseline across a collection of datasets. This is *not* surprising though: each dataset exhibits different characteristics and types or magnitudes of shifts that call for different methods (Benoit et al., ). Numerous analyses indeed confirm that no single method can handle a multitude of shifts (Wiles et al., ; Nguyen et al., ; Ye et al., ; Liang & Zou, ; Yang et al., ).

[style=citationFrame,userdefinedwidth=.90align=center,skipabove=3pt,skipbelow=0pt,innerbottommargin=4pt,innertopmargin=5pt,roundcorner=3pt,backgroundcolor=gray!5,linecolor=gray!85]
“It would be helpful for practitioners to be able to select the best approaches without requiring comprehensive evaluations and comparisons.” (Wiles et al., )

#### We posit that OOD generalization can be improved if we knew which algorithm to apply in each situation.

However, under complex real-world shifts, finding the right learning algorithm without trial and error is elusive for human experts.
We therefore investigate the possibility of *learning* to predict a priori, for a new unseen dataset, the algorithm that will produce the most robust model.
This *a priori* prediction contrasts with traditional
model selection that first requires training multiple models and often relies on restrictive heuristics
(Garg et al., ; Baek et al., ; Miller et al., ; Teney et al., ; Liu et al., ).
In a concurrent work, Bell et al. () proposed to select
an algorithm to deal with spurious correlations
based on past performance on benchmarks most similar to the target data.
In comparison, we target many types of shifts (spurious correlation, covariate shift, label shift) and propose a learning-based approach instead of similarity heuristics.

#### OOD-Chameleon .

We frame the algorithm selection as a classification over a set of candidate algorithms.
We train an algorithm selector named OOD-Chameleon in a setup akin to *meta-learning*
(Vanschoren, ; Öztürk et al., ) in two ways.
(1) It is trained on a *dataset of datasets* that exemplify diverse types, magnitudes, and combinations of shifts.
Concretely, we construct such a dataset of datasets by sampling from synthetic distributions or real datasets e.g. CelebA (Liu et al., ), in many controlled ways to simulate various distribution shifts.
(2) We seek to *learn to learn*, or learn to apply a learning algorithm, by discovering interactions between a dataset’s characteristics and the performance of candidate algorithms.
We evaluate the performance of various algorithms on the dataset of datasets, and we train the algorithm selector with supervision to predict the
relative performance of the algorithms given a statistical descriptor of a dataset
(see Figure 1).
We implement and evaluate training objectives such as regression, multi-label classification (Fürnkranz et al., ), and pairwise comparison (Bradley & Terry, ).

Our experiments start with a controllable setup to evaluate various design choices.
We then push the concept further with realistic image data.
Results show that the system consistently selects algorithms with significantly lower test error than any single candidate algorithm, on unseen datasets with complex types of distribution shifts.
We further verify that it achieves this by learning non-trivial, non-linear data/algorithm interactions.
More importantly, we show transfer across datasets by training the selector on CelebA-derived datasets,
then applying it to COCO (Lin et al., ).
As a byproduct, we demonstrate that the algorithm selector can reveal which dataset characteristics are important for any candidate algorithm to outperform another.

In summary, our findings call for improving OOD generalization by learning to better apply existing algorithms, instead of designing new ones.
Additionally, this line of research can help understand the applicability of existing algorithms, especially under complex conditions such as combined distribution shifts that are difficult to study theoretically.

Our contributions are summarized as follows.

- •
We formalize the task of *algorithm selection for OOD generalization* (Section 2). It consists in predicting the best strategy to obtain a robust model given a statistical descriptor of the dataset.
- •
We describe a reusable workflow to construct a *dataset of datasets* that exemplifies a variety of distribution shifts in different types, magnitudes, and combinations. (Section 3.1).
- •
We propose a demonstrator of the viability of the task (Section 3):
an algorithm selector trained with supervised learning to predict the most suitable algorithm from a set of candidates.
- •
We empirically verify that the proposed model predicts algorithms
leading to high OOD accuracy,
by learning non-trivial data/algorithm interactions (Section 4).
We also show that the model can reveal properties of datasets that make algorithms more effective than others (Section 3.4).

## 2 Formalizing the Algorithm Selection for OOD Generalization

### 2.1 Is the Selection of the Best Learning Algorithm Even Possible?

A universal solution to the selection of a learning algorithm cannot exist according to the no-free-lunch theorem (Wolpert & Macready, )).
The key here is to restrict ourselves to a *distribution of distribution shifts* that are likely in real-world data (Wiles et al., ; Goldblum et al., ).
We consider the three major types of shifts: covariate shifts (CS), label shifts (LS), and spurious correlations (SC).
Formally, given a joint distribution $P(X,Y)$ over inputs $X$ and labels $Y$,
the three types correspond to shifts of $P(X)$, $P(Y)$ and $P(Y|X)$.
Each sample $x\in X$ is typically characterized by both a robust feature $x_{c}\in X_{c}$ that is reliably predictive, and an attribute $a\in A$ that is not.
A covariate shift implies a variation of the attribute $a$ such as a shift in the background typically associated with a specific object in an image.
A shift of spurious correlations implies a variation of an attribute/label co-occurrences,
which means a shift on $P(Y|A)$ but not $P(Y|X_{c})$.
Because of the co-occurrence, a model could learn to rely on parts of the input related to the attribute.
This model would become unreliable on data where the co-occurrence has shifted.
Finally, to measure OOD performance, We use the standard worst-group accuracy (WGA) on test data.
A group $\mathcal{G}\in Y\times A$ refers to a unique attribute–label combination (Sagawa et al., ).

### 2.2 OOD Algorithm Selection as a Meta-Learning Task

Our eventual goal is to obtain a robust model given a dataset, referred to below as the OOD task.
An OOD task is defined by its dataset $D=D^{\mathrm{tr}}\cup D^{\mathrm{te}}=\left\{\left(x_{i},y_{i}\right)\right\}_
{i=1}^{n}\cup\left\{\left(x_{i},y_{i}\right)\right\}_{i=1}^{n_{\mathrm{te}}}$, where training and test data show potential distribution shifts.
Solving an OOD task means running a learning algorithm
$\mathcal{A}(\cdot):D^{\mathrm{tr}}\rightarrow h_{\theta}$
that takes the training set and produces a parametrized model.
We can then evaluate the performance of $\mathcal{A}$ by computing
$\mathrm{WGA}(\{h_{\theta}(x_{i})\}_{i=1}^{n_{\mathrm{te}}},\{y_{i}\}_{i=1}^{n_
{\mathrm{te}}})$ ($D^{\mathrm{te}}$ is not available during training).

To better solve OOD tasks, we propose to automate the OOD algorithm selection
(i.e. selecting the best $\mathcal{A}$ among candidates)
by learning from experiences over many OOD tasks.
The training data $\mathbb{D}$ (a meta-dataset) for this process is built from a dataset of datasets
that represent a variety of distribution shifts.
Each example in this meta-dataset
$\mathbb{D}=\{D_{j}^{\mathrm{tr}},\mathcal{A}_{j},P_{j}\}$ is an OOD task annotated with the performance of an algorithm on this task.
In practice, we feed $D^{\mathrm{tr}}$ into a
dataset descriptor (Rivolli et al., ; Jomaa et al., )
that summarize its distributional characteristics with a function $f(\cdot):D^{\mathrm{tr}}\rightarrow\mathbb{R}^{l}$, so that we can leverage vector-based models.
This makes $\mathbb{D}=\{f(D_{j}^{\mathrm{tr}}),\mathcal{A}_{j},P_{j}\}$.
Then, we expect to learn from $\mathbb{D}$
an algorithm selector $\phi(w,\cdot):D^{\mathrm{tr}}\rightarrow\mathcal{A}$ that takes a training set and predicts the most suitable algorithm(^1^11By abuse of notation, $\mathcal{A}$ represents in practice a one-hot identifier of an algorithm.).
We will describe in Section 3.2 several realizations of the algorithm selector.
A straightforward option is a mapping from a dataset descriptor
$f(D^{\mathrm{tr}})$
and algorithm identifier $\mathcal{A}$
to its predicted performance, i.e. $\phi(w,\cdot):f(D^{\mathrm{tr}})\times\mathcal{A}\rightarrow\mathbb{R}$ that is trained by solving:

$$ $\min_{w}\mathbb{E}_{\{f(D_{j}^{\mathrm{tr}}),\mathcal{A}_{j},P_{j}\}\sim \mathbb{D}}\;\mathcal{L}_{O}(\phi(w,\{f(D_{j}^{\mathrm{tr}}),\mathcal{A}_{j}\} ),P_{j})$ (1) $$

where $\mathcal{L}_{O}$ is a loss function such as the MSE.
The trained $\phi(w,\cdot)$ can then be used on any new dataset (representing a new unseen OOD task) to predict the performance of all the candidate algorithms. The best algorithm is eventually used on the new dataset to obtain a robust downstream model.

## 3 OOD-Chameleon : Learning When to Use a Learning Algorithm

We now describe our solution to tackle OOD algorithm selection including *three consecutive steps*:

- 1.
Obtaining a collection of example datasets with a variety of distribution shifts to learn from.
- 2.
Assembling the meta-dataset $\mathbb{D}$. That is, training candidate algorithms on each dataset to get the corresponding performance, and summarizing each dataset with some dataset descriptor $f(\cdot)$.
- 3.
Training an algorithm selector on the meta-dataset to learn robust data/algorithm relations.

Each step poses special challenges which we address as follows.

### 3.1 Constructing Datasets with Various Distribution Shifts

We first generate a dataset of datasets that exhibit
three types of shifts in various combinations and degrees.
The generation procedure takes in: (1) a triple
$(d_{\mathrm{cs}},d_{\mathrm{ls}},d_{\mathrm{sc}})\in[0,1]^{3}$
that specifies the degree of covariate shift (CS), label shift (LS), and spurious correlation (SC), and (2) the size of the training set $n$.
It computes the required number of samples of each group necessary to achieve these properties.
The actual dataset can then be built with these numbers using synthetic data
(Section 3.3) or by resampling an existing real dataset such as CelebA (Liu et al., ) (Section 4).

Figure: Figure 2: Illustrative example of our distribution shift quantification.
Refer to caption: x2.png

#### Quantifying distribution shifts.

We need a way to specify the degree of each type of shift.
Prior work by Yang et al. () has used information-theoretic measures
to quantify the degrees of SC, LS, and CS respectively as
the normalized mutual information $I(a;y)$ between labels and attributes,
entropy of class $H(y)$, and
entropy of attributes $H(a)$.
However, we cannot use them to directly compute the required number of samples for each group.
Hence we propose an alternative illustrated
in Figure 2 with a 2-way classification of shapes with two color attributes.
The four groups correspond to $\mathcal{G}_{1}=\{i|y_{i}=1,a_{i}=1\}$, $\mathcal{G}_{2}=\{i|y_{i}=-1,a_{i}=1\}$, $\mathcal{G}_{3}=\{i|y_{i}=-1,a_{i}=-1\}$, $\mathcal{G}_{4}=\{i|y_{i}=1,a_{i}=-1\}$.
We define the degree of SC as the ratio of samples where class labels and attribute labels agree,
i.e. where a correct classification of the attribute entails a correct classification of the class
We define the degrees of LS and CS as the ratio of class/attribute as follows
(numerators colored as in Figure 2):

$$ $d_{\mathrm{sc}}=\frac{\hbox{\pagecolor[RGB]{225, 236, 216}$|\mathcal{G}_{1}|+| \mathcal{G}_{3}|$}}{\sum_{i}|\mathcal{G}_{i}|},\quad d_{\mathrm{ls}}=\frac{ \hbox{\pagecolor[RGB]{253, 243, 219}$|\mathcal{G}_{1}|+|\mathcal{G}_{4}|$}}{ \sum_{i}|\mathcal{G}_{i}|},\quad d_{\mathrm{cs}}=\frac{\hbox{\pagecolor[RGB]{2 52, 229, 227}$|\mathcal{G}_{1}|+|\mathcal{G}_{2}|$}}{\sum_{i}|\mathcal{G}_{i}|},$ (2) $$

where $|\cdot|$ is the set cardinality.
The three degrees are in $[0,1]$ by definition, and $\sum_{i}|\mathcal{G}_{i}|=n$ size of $D^{\mathrm{tr}}$.
To construct a dataset with desired shifts, we start with the three desired degrees and the training set size,
then solve linear equations for $|\mathcal{G}_{i}|$ and obtain the required group sizes in the training set.
We sample a balanced test set $D^{\mathrm{te}}$ with $|\mathcal{G}_{i}|=n_{\mathrm{te}}/i$.
See Appendix A for additional explanations.

### 3.2 Formulations of the Algorithm Selector

Given a collection of datasets $\{D_{j}\}_{j=1}^{N}$ created as described above,
we apply a set of algorithms $\{\mathcal{A}_{m}\}_{m=1}^{M}$ on each.
Each case yields a downstream model with OOD performance
$P_{jm}$
that we store in a meta-dataset
$\mathbb{D}=\{f(D_{j}^{\mathrm{tr}}),\mathcal{A}_{m},P_{jm}\}_{j,m}$ (of size $MN$)
where $f(\cdot):D^{\mathrm{tr}}\rightarrow\mathbb{R}^{l}$ is the dataset descriptor (will discuss in Section 3.3).
This meta-dataset is used to train the algorithm selector $\phi$
(an MLP in most of our experiments)
with one of the three objectives described below
The different formulations are visually summarized in Figure 3.

Figure: Figure 3: We propose three possible objectives to train the algorithm selector. The meta-dataset $\mathbb{D}$ contains here the performance of three algorithms $\mathcal{A}_{\{1,2,3\}}$ on one dataset $D_{\mathrm{I}}$. Regression (left) estimates the algorithms’ absolute performance. MLC (middle) and PPL (right) estimate the binarized (unary and pairwise) suitability of the algorithms.
Refer to caption: x7.png

#### Formulation 1 (Regression): classification via regression.

Equation 1 tackles the algorithm selection task with a classification via regression.
The algorithm selector $\phi(w,\cdot):f(D^{\mathrm{tr}})\times\mathcal{A}\rightarrow\mathbb{R}$ takes the dataset descriptors and a one-hot algorithm vector as input, predicts the OOD performance, and then chooses the algorithm with the highest one.
This may be suboptimal because of (1) the mismatch between the goal of directly selecting (i.e., classifying) suitable algorithms, and (2) a regression being often more difficult than classification with neural networks (Devroye et al., ).
This motivates two alternative formulations as pure classification tasks.

#### Formulation 2 (MLC): multi-label classification.

For each dataset $D_{j}$, we have $M$ (the number of algorithms) records $\{f(D_{j}^{\mathrm{tr}}),\mathcal{A}_{m},P_{jm}\}_{m=1}^{M}$ in the meta-dataset $\mathbb{D}$.
We aggregate each such set of $M$ records into a single training sample $\{f(D_{j}^{\mathrm{tr}}),Y_{\mathcal{A}}\}$ where $Y_{\mathcal{A}}\in\{0,1\}^{M}$ is a one- or multi-hot vector indicating the suitability of one or several algorithms on $D_{j}$.
An algorithm is considered suitable if $(P_{jm}\,-\,\min_{m}\!P_{jm})\leq\epsilon$ for a small threshold $\epsilon$ (e.g. $0.05$).
This aggregation converts the performance numbers into discrete labels and also serves as “denoising”
because we consider algorithms with close performance similarly suitable.
The process results in a smaller meta-dataset (from $MN$ to $N$) but allows for learning more robust data/algorithm interactions because of denoising.
We train the algorithm selection as a
binary multi-label classifier $\phi(w,\cdot):f(D^{\mathrm{tr}})\rightarrow\{0,1\}^{M}$
with a cross-entropy objective $\min_{w}\mathcal{L}(\phi(w,f(D_{j}^{\mathrm{tr}})),Y_{\mathcal{A}})$.

#### Formulation 3 (PPL): pairwise preference learning.

Going one step further, an alternative formulation decomposes the M-way multi-label classification into $\binom{M}{2}$classifications (Hüllermeier et al., ) across pairs of algorithms.
The intuition is that pairwise comparisons are easier than comparing all the candidates (Bradley & Terry, )
as recently shown i.a. in the alignment of language models (Ouyang et al., ).
We train $\binom{M}{2}$ pairwise classifiers $\phi_{km}(w,\cdot):f(D^{\mathrm{tr}})\rightarrow\{\texttt{win},\texttt{lose},
\texttt{tie}\}$ to predict the relative ranking of $\mathcal{A}_{k}$ and $\mathcal{A}_{m}$.
They are considered on par when $|P_{jk}-P_{jm}|\leq\epsilon$.
Formally, these 3-way classifiers are trained on $\{f(D_{j}^{\mathrm{tr}}),Y_{\mathcal{A}}\},j\in[1,...,N]$, where $Y_{\mathcal{A}}\in\{\texttt{win},\texttt{lose},\texttt{tie}\}$.
At test time,
for a target dataset, we aggregate the $\binom{M}{2}$ predictions using Copeland’s classical voting method (Saari & Merlin, ).
It starts from 0 for all algorithms and adds/subtracts 1 for the winner/loser of each pairwise prediction, and does nothing for ties.
The final scores give a ranking across all algorithms from which we select the top value.

### 3.3 Dataset Descriptors: A Case Study with Controllable Experiments

Now that we have built the algorithm selector, we turn our attention to its input – the vectorized datasets (i.e., dataset descriptors).
The dataset descriptors should summarize properties relevant to the performance of the various algorithms.
Recent work (Nagarajan et al., ; Hermann et al., ; Yang et al., ; Chen et al., ; Ye et al., ; Wang et al., ) discovered various properties related to OOD performance that could serve as dataset descriptors. However, many are difficult or impossible to measure before training, or work only under restricted conditions.
Other works on learning model selection (Arango et al., ; Öztürk et al., )
use simple descriptors (e.g., number of training samples, image channels, number of classes, etc.) that clearly cannot predict OOD performance.

We propose two categories of properties to include in dataset descriptors: (1) distribution shift characteristics and (2) data complexity characteristics.
We hypothesize that the former includes the degrees of the distribution shifts ($d_{\mathrm{sc}}$, $d_{\mathrm{ls}}$, $d_{\mathrm{cs}}$ in Equation 2), and the availability(^2^22 Similar concepts exist in prior works: signal/noise ratio (Yang et al., ), magnitude (Wang et al., ; Joshi et al., ), simplicity (Qiu et al., ), and spurious/core information ratio (Sagawa et al., ).) $r$ of the spurious correlation (i.e., how easily the model relies on the spurious feature to make predictions).
And the latter includes the size of the training set $n$ and the input dimensionality $d$ (e.g. image resolution in vision data).

#### Controllable experiments.

We investigate the relevance of the proposed descriptors with a synthetic test case.
We consider the binary classification from Figure 2.
The input $X$’s distribution follows the modified synthetic example from Sagawa et al. ().
The distribution of each group is defined by their input $x=[x_{c},x_{a}]\in\mathbb{R}^{2d}$,
with $x_{c}$ and $x_{a}$ of dimension $d$ generated from Gaussian distribution:

$$ $x_{c}\mid y\sim\mathcal{N}\left(y\mathbf{1},\sigma_{\text{c }}^{2}I_{d}\right) ,\quad x_{a}\mid y\sim\mathcal{N}\left(a\mathbf{1},\sigma_{\text{a }}^{2}I_{d}\right)$ $$

The availability of the spurious features is defined as $r=\sigma_{\text{c }}^{2}/\sigma_{\text{a }}^{2}$
(more available when higher).
Following Section 3.1, we create $N=7,392$ datasets $D_{1,...,N}$ spanning different $d_{\mathrm{sc}},d_{\mathrm{ls}},d_{\mathrm{cs}}$, training set sizes $n$, input dimensionality $d$, and availability $r$
(details in Appendix C).

**Table 1: Results on synthetic experiments. The learned algorithm selector predicts algorithms with low worst-group test error (average over 2,000 unseen datasets and 3 seeds).**
| Metrics | Oracle<br>Selection | Random<br>Selection | Global<br>Best | MLC<br>(Naive descriptors) | Regression<br>(Ours) | MLC<br>(Ours) | PPL<br>(Ours) |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 0–1 ACC. (%) $\uparrow$ | 100 | 62.9±0.6 | 72.5±0.7 | 52.1±0.1 | 79.7±0.7 | 86.3±0.4 | 90.8±0.9 |
| Worst-group error (%) $\downarrow$ | 19.0 | 24.0±0.1 | 22.7±0.1 | 23.9±0.2 | 20.4±0.3 | 19.9±0.1 | 20.1±0.1 |
| Remarks | Upper<br>bound | Non-parametrized | Descriptors from<br>Öztürk et al. () | Eq. 1 | multi-label<br>classification | pairwise<br>comparison |  |

#### Experimental setup.

We construct the meta-dataset $\mathbb{D}$ with the created collection of datasets, train the algorithm selector with different objectives on it, and then evaluate how well the algorithm selector predicts suitable algorithms for unseen datasets.
Other relevant details (see also Appendix C):

- •
Candidate algorithms.
We select 5 algorithms, namely ERM (Vapnik, ), GroupDRO (Sagawa et al., ), oversampling the minority groups, undersampling the majority groups, and logits correction (Nagarajan et al., ) (i.e. adjust the prediction logits with a temperature), because: (1) they are shown to perform comparably with others (Nguyen et al., ; Gulrajani & Lopez-Paz, ; Yang et al., ), (2) do not require extensive hyperparameter tuning, (3) can handle different distribution shifts (Nguyen et al., ) and (4) span different types of approaches, namely regularization-based, reweighting-based, margin-based and standard ERM. Including more algorithms is straightforward.
- •
Obtaining OOD performance on the collection of datasets.
We obtain each algorithm’s worst-group error $P_{jm}$ on each dataset’s test set $D_{j}^{\mathrm{te}}$.
We use a linear classifier for training on each dataset because (1) it is sufficient to solve the synthetic example and was also used by Sagawa et al. (), (2) it is relevant to the common setting of linear probing over frozen features (Setlur et al., ; You et al., ).
- •
Evaluation.
We create around 2,000 datasets with unseen properties (i.e. different and unseen dataset descriptors)
to test the generalizability of the algorithm selector.
- •
Algorithm selection baselines.
(1) Random selection: randomly selecting an algorithm per dataset.
(2) Global best (GB): choosing the single top algorithm based on its performance over the whole meta-dataset.
(3) MLC  (Naive descriptors): MLC with the naive dataset descriptors from Öztürk et al. (). This is useful to indicate whether our dataset descriptors provide useful additional information.
(4) Oracle selection: using the ground truth best algorithm per dataset.

Figure: Figure 4: (Left) OOD algorithms perform differently across datasets. We compare pairs of algorithms and show the histogram of differences in worst-group test error. (Middle) The generalizability of the algorithm selector (MLC) improves with a larger meta-dataset. (Right) We estimate the importance of dataset descriptors with leave-one-descriptor-out training of the algorithm selector.
Refer to caption: x8.png

#### Results.

In Table 1, we show that the learned algorithm selectors generalize to unseen datasets.
We examine the 0–1 accuracy, which considers an algorithm prediction on an unseen dataset as correct if it belongs to the “ground truth” suitable algorithms as defined earlier in Section 3.2.
We also look at the worst-group error of the selected algorithms, averaged across unseen datasets.
We see that (1) our formulations accurately predict suitable OOD algorithms, with significantly higher 0–1 accuracy and lower worst-group error than the baselines.
(2) The algorithm selectors generalize significantly better with our dataset descriptors in lieu of naive descriptors, c.f. columns 4 and 6.
(3) Comparing our three formulations (columns 4, 5, 6) shows that a classification objective is significantly better than a regression.

In Figure 4 (left), we verify that the different OOD algorithms perform differently across datasets (each count in the histogram is a dataset).
This confirms that using the right algorithm for the right dataset improves OOD generalization.
In Figure 4 (middle), we show that the algorithm selector (MLC) generalizes better with a larger meta-dataset, yet it already significantly outperforms the best non-parametrized baseline (Global best) even with a small meta-dataset.
In Figure 4 (right), we conduct a leave-one-descriptor-out training of MLC by excluding one part of the descriptor at a time.
The accuracy drops (c.f. the leftmost bar) reveal the importance of each piece of information for an accurate prediction.
We see that the degree of shift and data complexity matter most,
specifically the input dimensionality $d$, the availability of the spurious feature $r$, and the degree of spurious correlation $d_{\mathrm{sc}}$.

### 3.4 Attributing Algorithm Effectiveness to Data Characteristics

Figure: Figure 5: Leave-one-descriptor-out training of pairwise algorithm selectors. The accuracy drops reveal decisive factors for one algorithm to outperform another.
Refer to caption: x11.png

We take an even closer look at the learned data-algorithm interactions with leave-one-descriptor-out training of pairwise algorithm selectors (i.e., selecting from only two algorithms).
In Figure 5, for each pair of algorithms, the performance drop of each bar compared to the leftmost bar (“N/A”) indicates the significance of the corresponding information for distinguishing the two algorithms.
For example, when comparing over- and undersampling, the data size $n$ and degree of spurious correlation $d_{\mathrm{sc}}$ matter most.
We find this to be consistent with the analysis in Nguyen et al. () that implies that, while undersampling can cope with more distribution shifts than oversampling,
it is inferior when the number of samples for the minority group is too small (i.e. when $n$ or $d_{\mathrm{sc}}$ is too small).
This approach can thus help discover data characteristics important for one algorithm to outperform another, and better understand the applicability of existing algorithms.
We observe for example that the importance of some descriptors varies for other pairs of algorithms
(Figure 5 middle/right), which could deserve further investigations.

## 4 Towards Realistic OOD Algorithm Selection

We now push the concept further with realistic data to answer the following research questions.
(RQ1) Is the learned algorithm selection also effective with datasets of real images?
(RQ2) Does our algorithm selector, trained on the semi-synthetic datasets built from CelebA for example,
transfer to unseen datasets from another domain (e.g. COCO (Lin et al., ))?
(RQ3) How is the system affected by
different dataset descriptors and different training variations of OOD tasks (linear probing vs. fine-tuning)?
(RQ4) How complex are the learned data-algorithm interactions?

#### Experimental setup.

The setup resembles that of Section 3.3
(see Appendix D for more details).

- •
Dataset of datasets.
We generate 1,056 example datasets from CelebA (Liu et al., )
with various sizes, types of shifts, etc.
We simulate various “availabilities” of the spurious feature by
using various annotations from CelebA, e.g. mouth slightly open as class label and
wearing lipstick as spurious attribute (see Table 8).
- •
Dataset descriptors.
We now *estimate* the availability of spurious feature
(rather than using ground truth values as in Section 3.3) with
$r=\sum_{y}d_{y}/\sum_{a}d_{a}$, where $d_{y}$ and $d_{a}$ are average distances of the samples’ embeddings to the cluster center of labels or attributes, respectively.
Using estimated availabilities allows for generalizing to unseen availabilities,
see Appendix D.1 for the rationale and details.
- •
Obtaining OOD performance on the collection of datasets.
We use a pre-trained ResNet18 (He et al., ) or CLIP model (ViT-B/32) (Radford et al., ) to solve each OOD task and obtain the “ground truth” performance of each algorithm.
We do a linear probing or a fine-tuning (on ResNet18 for the experiment of Table 6).
- •
Evaluation. We create 264 and 47 unseen datasets with CelebA and COCO, respectively, and use the {cat, dog} and {indoor, outdoor} images for COCO. These datasets are not new, but to our knowledge, recent datasets such as MetaShift (Liang & Zou, ) do not have a sufficient number of samples to create satisfying datasets.

#### RQ1-RQ2: Algorithm selection is learnable on real-world data.

In Table 2, we see that all three formulations of OOD-Chameleon can still select algorithms for unseen OOD datasets from both CelebA and COCO with significantly lower worst-group error and higher 0–1 Accuracy than any baselines.
The results on COCO also verify the robustness of our dataset descriptors in capturing general properties relevant to the performance of the algorithms in a way that transfers across datasets.
Additionally, we see that PPL achieves the best performance among the proposed three realizations, using classification instead of a regression objective, as well as the learning of pairwise comparison
(see additional discussion in Appendix B).

In Table 4, we compare PPL with single algorithm baselines,
where a single algorithm is used for all unseen datasets.
We see that our method performs an *adaptive* selection of algorithms for each unseen dataset, thereby achieving lower worst-group error than any single algorithm.
Furthermore, the ratios of the selected algorithms across unseen datasets are close to the ground truth oracle selection.
This also shows that choosing algorithms according to the nature of the dataset is both learnable and helpful.

**Table 2: Results on algorithm selection for unseen CelebA and COCO datasets. Algorithm selectors are trained on the meta-dataset generated from CelebA and evaluated on unseen CelebA or COCO datasets. ResNet18 and CLIP (ViT-B/32) refer to the models use in the OOD tasks.**
| Methods | CelebA | COCO |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| ResNet18 | CLIP (ViT-B/32) | ResNet18 | CLIP (ViT-B/32) |  |  |  |  |  |
| 0-1 ACC.  $\uparrow$ | WG error $\downarrow$ | 0-1 ACC. $\uparrow$ | WG error $\downarrow$ | 0-1 ACC.  $\uparrow$ | WG error $\downarrow$ | 0-1 ACC. $\uparrow$ | WG error $\downarrow$ |  |
| Oracle Selection | 100 | 40.4 ±0.2 | 100 | 31.8 ±0.3 | 100 | 33.2 | 100 | 20.9 |
| Random Selection | 25.0 ±1.7 | 49.8 ±0.5 | 26.7 ±0.9 | 41.6 ±0.1 | 31.9 ±0.3 | 42.0 ±0.2 | 38.3 ±0.2 | 28.0 ±0.2 |
| Global Best (GB) | 44.8 ±1.0 | 45.9 ±0.3 | 43.0 ±2.2 | 38.7 ±0.2 | 42.5 ±0.1 | 37.3 ±0.3 | 46.8 ±0.4 | 26.2 ±0.3 |
| Regression (Ours) | 75.4 ±1.5 | 42.5 ±0.6 | 72.9 ±1.1 | 34.3 ±0.3 | 51.1 ±1.0 | 37.2 ±0.5 | 68.8 ±0.6 | 24.0 ±0.5 |
| MLC (Ours) | 69.1 ±2.1 | 42.7 ±0.5 | 80.6 ±0.4 | 33.5 ±0.4 | 55.3 ±0.7 | 36.4 ±0.3 | 74.4 ±1.1 | 23.6 ±0.7 |
| PPL (Ours) | 80.0 ±1.1 | 42.0 ±0.2 | 83.7 ±0.6 | 33.0 ±0.3 | 65.9 ±0.5 | 35.9 ±0.3 | 75.8 ±0.5 | 23.4 ±0.4 |

**Table 3: Learning to adaptively use OOD algorithms leads to lower worst-group errors than single algorithms. The bars are colored by the ratios of algorithms.**
| Methods | ResNet18 | CLIP (ViT-B/32) |  |  |
| --- | --- | --- | --- | --- |
| Alg. Selection | WG error $\downarrow$ | Alg. Selection | WG error $\downarrow$ |  |
| Oracle Selection |  | 40.4 ±0.2 |  | 31.8 ±0.3 |
| ERM |  | 58.8 ±0.3 |  | 49.9 ±0.4 |
| GroupDRO |  | 46.6 ±0.2 |  | 41.3 ±0.2 |
| Logits Correction |  | 54.1 ±0.5 |  | 42.6 ±0.4 |
| UnderSampling |  | 43.1 ±0.4 |  | 34.6 ±0.2 |
| OverSampling |  | 46.9 ±0.3 |  | 41.5 ±0.1 |
| PPL (Ours) |  | 42.0 ±0.2 |  | 33.0 ±0.3 |

#### RQ3: Ablation studies.

We analyze the impact of dataset descriptors and training paradigms for the OOD tasks.
In Table 6, we show that the simple dataset descriptors from Öztürk et al. () are clearly outperform by ours.
In Table 6, we verify that the algorithm selector works well with both linear probing and fine-tuning with CelebA.
This is necessary to check because, solving the OOD tasks by different training paradigms affects the algorithms’ OOD performance $P_{jm}$ and therefore changes the distribution of meta-dataset $\mathbb{D}=\{f(D_{j}^{\mathrm{tr}}),\mathcal{A}_{m},P_{jm}\}$.
The results indicate that the learned algorithm selector can also accurately select suitable algorithms when the models for the OOD tasks become over-parametrized in the case of fine-tuning.
Furthermore, in Appendix E, we evaluate the effectiveness of our model with estimated dataset descriptors when the information, such as attributes for each sample, cannot be easily obtained at test time.

#### RQ4: The algorithm selector learns non-trivial data-algorithm interactions.

We evaluate the complexity of the learned data-algorithm interactions by comparing
various architectures for the algorithm selector $\phi(\cdot,w)$
(see Table 4; “Linear (ResNet)” means for example
a linear model for the selector and a ResNet18 for the OOD task).
First, we see that a linear model is significantly worse than an MLP. This shows that
the model makes accurate predictions on the basis of non-linear interactions between datasets’ characteristics and algorithms’ performance.
Second, we see that a k-NN is also significantly worse than an MLP.
This shows that the model works not only by memorizing a large number of example shifts, which a k-NN could also do. On the contrary, accurate predictions on unseen datasets require non-trivial generalization.

## 5 Related Work

OOD generalization has been widely studied but
several benchmark studies concluded that there is no one-fits-all solution to distribution shifts
(Gulrajani & Lopez-Paz, ; Wiles et al., ; Nguyen et al., ; Ye et al., ; Liang & Zou, ; Yang et al., ; Bell et al., ).
These meta studies show that OOD algorithms perform differently in different situations.
An algorithm only shines when its underlying assumptions are met.
This is the motivation for our goal of *adaptively* using existing algorithms,
and investigating whether this process can be learned and automated.

**Table 5: Evaluation of training paradigms for OOD tasks. The model generalizes on both linear probing and fine-tuning.**
| Methods | Linear probing | Fine-tuning |  |  |
| --- | --- | --- | --- | --- |
| 0-1 ACC.  $\uparrow$ | WG error $\downarrow$ | 0-1 ACC. $\uparrow$ | WG error $\downarrow$ |  |
| Oracle Selection | 100 | 40.4 ±0.2 | 100 | 32.3 ±0.4 |
| Regression (Ours) | 75.4 ±1.5 | 42.5 ±0.6 | 73.6 ±1.8 | 34.5 ±0.3 |
| MLC (Ours) | 69.1 ±2.1 | 42.7 ±0.5 | 67.8 ±1.3 | 34.8 ±0.4 |
| PPL (Ours) | 80.0 ±1.1 | 42.0 ±0.2 | 79.2 ±1.3 | 34.1 ±0.3 |

Algorithm selection.
Model selection (Forster, ; Raschka, ) and algorithm selection (Rice, ; Kerschke et al., )
are integral parts of any machine learning workflow.
Regarding OOD generalization, a series of works (Liu et al., ; Baek et al., ; Garg et al., ; Miller et al., ; Lu et al., ) use heuristics to estimate a models’ OOD performance on a target dataset when no labeled OOD data is available.
These heuristics have one or several of these downsides: (1) they can only be estimated after training, (2) they require (unlabeled) test data, and (3) they work only under restricted conditions.
In contrast, our work aims for *a priori* selection of the best algorithm, i.e. before training on the target dataset.

Concurrently to our work, Bell et al. () identified a very similar motivation.
They proposed to select among algorithms that deal with spurious correlations
based on their performance on benchmarks most similar to the target dataset.
The differences with our work are: (1) we use a *learning* approach rather than a similarity heuristic, (2) our learning process relies on *semi-synthetic* data rather than existing benchmarks, which helps cover a broader set of distribution shifts, and (3) we also consider *label and covariate shifts* and their combinations, not only spurious correlations.

Meta-learning.
Our “learning-to-learn” process resembles meta-learning (Vilalta & Drissi, ; Hospedales et al., ) in that it carries over prior experience from historical tasks to future similar ones.
Achille et al. (); Öztürk et al. (); Arango et al. (); Zhang et al. () learn to select among pretrained models for downstream tasks
or for outlier detection Zhao et al. ().
They either first require training a model on the target dataset
or they are not suited to OOD generalization.

AutoML.
Our work is distantly related to AutoML, which aims to identify complete ML workflows, often by informed trial-and-error
(Hutter et al., ; He et al., ). Our work differs in its aim for *a priori* algorithm selection, and its side benefit of unveiling datasets’ properties that are predictive of the applicability of existing algorithms.

## 6 Conclusions

This work explored a new avenue for improving OOD generalization by better using existing algorithms instead of creating new ones.
We formalized the task of *OOD algorithm selection*
and took the first step to learn it.
We treated it as a classification over candidate algorithms,
learned with supervision from a *dataset of datasets*
representing a variety of distribution shifts.
The resulting system not only predicts low-test-error algorithms on unseen datasets,
but also reveals key properties of datasets that allow algorithms to outperform one another.
More could be learned in the future about existing algorithms e.g. by training the selector as an interpretable decision tree.

#### Limitations and future work.

The proposed solution served to verify the viability of the new task.
Several limitations and promising directions remain to be addressed in future work.
(1) Candidate algorithms.
We only included a few algorithms representative of broad categories, and known to be simple but effective in different settings.
It is straightforward to include more algorithms and variations thereof (e.g. different hyperparameters).
It will be interesting whether the approach remains accurate when differences across algorithms are fine-grained.
(2) Real-world settings. The approach needs to be applied to real-world data (e.g. from WILDS, Koh et al. ()) and larger-scale models. This will evaluate the limits of transferability of the learned selector, as started in Section 4.
(3) Dataset descriptors. A promising direction to improve transferability is to replace our dataset descriptors with learned representations of datasets e.g. with Set Transformers Lee et al. ()
or Dataset2Vec Jomaa et al. ().

## Appendix

We provide more details and results omitted in the main paper, summarized as follows.

- •
Appendix A details how we construct datasets with desired distribution shifts.
- •
Appendix B provides intuitions why the 3 formulations of the selector perform differently.
- •
Appendix C describes details on the setup of the controllable experiments from Section 3.3.
- •
Appendix D describes details on the setup of the realistic experiments from Section 4.
- •
Appendix E evaluates the use of estimated dataset descriptors
as input to the selector.

## Appendix A Meta-dataset Construction

In Section 3.1, we describe a framework that allows for constructing datasets with diverse distribution shifts by sampling from synthetic distributions or an existing dataset, here we provide more details and examples on this front.
There are two use cases in Section 3.3 and Section 4 respectively, where in both cases we know the distribution of each group (recall that the combinations of different values of attribute $a$ and class $y$ form different groups).
Specifically, in Section 3.3, we have the group distributions as Gaussian distributions so that we can sample the desired numbers of samples from those distributions, while in Section 4 we have a decent amount of samples (in CelebA) from each group distributions and we can also sample the desired numbers of samples from each group distributions.

In Equation 2, we define the degrees of distribution shifts as a function of the number of samples for each group.
Therefore, to obtain a dataset with specific degrees of distribution shifts, one only needs to solve the number of samples for each group and sample them from the group distribution.
Note that the number of samples can be scaled up or down depending on the size of the dataset we want.
All of the constraints to be solved are therefore:

$$ $\displaystyle d_{\mathrm{sc}}=\frac{|\mathcal{G}_{1}|+|\mathcal{G}_{4}|}{\sum_ {i}|\mathcal{G}_{i}|},\quad d_{\mathrm{ls}}$ $\displaystyle=\frac{|\mathcal{G}_{1}|+|\mathcal{G}_{3}|}{\sum_{i}|\mathcal{G}_ {i}|},\quad d_{\mathrm{cs}}=\frac{|\mathcal{G}_{1}|+|\mathcal{G}_{2}|}{\sum_{i }|\mathcal{G}_{i}|},$ (3) $\displaystyle\sum_{i}|\mathcal{G}_{i}|$ $\displaystyle=n,\quad(|\mathcal{G}_{i}|\geq 0)$ $\displaystyle 0\leq d_{\mathrm{sc}}\leq 1,\quad 0$ $\displaystyle\leq d_{\mathrm{ls}}\leq 1,\quad 0\leq d_{\mathrm{cs}}\leq 1,$ $$

Solving the constraints gives the solution set of the degrees of distribution shifts, as shown in Figure 6.
We see that not any value in the cube can be chosen because of the constraint $|\mathcal{G}_{i}|\geq 0$ for $\forall i$.

Figure: Figure 6: The feasible degrees of spurious correlation ($d_{\mathrm{sc}}$), covariate shift ($d_{\mathrm{cs}}$) and label shift ($d_{\mathrm{ls}}$).
Refer to caption: x26.png

We can then generate various datasets by varying: (1) the degrees of distribution shifts, (2) the size of the dataset, and (3) the group distributions. Note that by definition when given a $d_{\mathrm{(\cdot)}}=0.5$, it means the absence of the corresponding type of distribution shift.
This framework can therefore generate combinations of shifts in types and degrees.

## Appendix B Discussions on the Algorithm Selector

While achieving the same goal of predicting the suitable algorithms given the descriptors of the target dataset, the three formulations of the algorithm sector mentioned in Section 3.2 perform differently as verified in Section 3.3 and Section 4.
Here we briefly discuss our intuition on this front.

The disadvantage of regression is that, it is hard to learn robust information from the subtle differences in performance.
These subtle differences in performance between algorithms can be caused by the variances of training randomness.
Therefore, a regression model trained on continuous performance can be disturbed by the variances of OOD task training.

Transforming the continuous performance into discrete labels and use classification models (what we called a ’denoising’ step) is the key to learning robust information from the meta-dataset.
Benefiting from this step, the multi-label classification (MLC) trains an end-to-end classifier to take the dataset descriptors as input and predict which algorithm is ’suitable’ on the target dataset.
It is verified to perform significantly better than the regression most of the time.

Finally, leveraging pairwise comparison (PPL) is observed to outperform MLC in many cases.
While a future analysis on this front is needed, our hypotheses are that (1) pairwise comparison is easier than comparing all the algorithms at once, which is consistent with our observation that higher accuracies are achieved on each pairwise classifiers (many achieved above 90% and some were close to 100% perfect accuracy), and (2) pairwise classifiers can parameterize more nuanced data-algorithm interactions, while MLC as a single classifier, only learns a more global view.
This becomes more clear when comparing Figure 4-right and Figure 5, we see that there exist different ’patterns’ of data-algorithm interactions (exemplified by the importance of dataset descriptors) in different pairwise classifiers.

## Appendix C Detailed Setup of the Controllable Experiments

We provide the detailed experimental setup for the controllable experiments in Section 3.3.

#### Dataset of datasets.

In total, we created 9,240 datasets, see Table 7 for the statistics for these datasets.
Specifically, we generate the training sets of the datasets with the combinations of values in Table 7, and for the degrees of distribution shifts, we consider 2 cases: (1) 3 shifts (spurious correlation, covariate shift and label shift) all present each in different degrees, we uniformly sampled 30 different triple degrees, and (3) there is only 1 shift present, in this case for each shift we 9 different values shown in the table (therefore in total $3*9-2=25$ different triple degrees).
We generate their test sets with the same number of samples as its training set for each dataset, but keep the number of samples the same for all groups (therefore balanced test sets with all $d_{(\cdot)}=0.5$).
We randomly split these datasets into 4:1 as the dataset of datasets for training the algorithm selector, and the unseen datasets for evaluation.

**Table 7: Statistics for the dataset of datasets in controllable synthetic experiments.**
| Statistics | Value |
| --- | --- |
| Size of training set | {200, 500, 1000, 2000, 3000, 5000, 10000} |
| Input dimensionality | {2, 10, 50, 100} |
| Availability $r=\sigma_{c}^{2}/\sigma_{a}^{2}$ | {1, 5, 10, 20, 50, 100} |
| 3 shifts | uniformly sampled 30 feasible degrees (Figure 6) |
| 1 shift | {0.01, 0.05, 0.1, 0.3, 0.5, 0.7, 0.9, 0.95, 0.99} |

#### Algorithm selector.

In all formulations of the algorithm selector mentioned in Section 3.2, we use 4-layer MLPs to parameterize the algorithm selector, because we found a shallower or simpler model underfits (see Table 4) while a deeper model does not provide more improvements.

#### OOD tasks.

To solve the OOD tasks defined by each dataset in the dataset of datasets, we use Adam optimizer with default hyperparameters, along with l2 regularization. We train for 1000 epochs to ensure convergence on this synthetic example.

## Appendix D Detailed Setup of the Realistic Experiments

### D.1 Availability of the Spurious Features

In the controllable experiments in Section 3.3, we compute the availability of spurious features as $r=\sigma_{c}^{2}/\sigma_{a}^{2}$, following the spurious-core information ratio defined in Sagawa et al. ().
The higher the $r$, the more signal there is about the spurious attribute in the spurious features, relative to the signal about the label in the core features.

However, in real-world data (Section 4), it is *not* straightforward how to generate the dataset of datasets with diverse $r$.
To tackle this, we use different attribute pairs (one as the label attribute, i.e. the attribute we want to classify, and the other as spurious attribute) as shown in Table 8, to account for different availability of spurious features.
Intuitively, the obviousness of different types of attributes (in terms of size, color, etc) signifies different availability of the spurious feature (caused by the attribute).

**Table 8: Attribute pairs in CelebA (Liu et al., ) that are used to construct different availability of the spurious feature.**
| Label attribute | Spurious attribute |
| --- | --- |
| Mouth Slightly Open | Wearing Lipstick |
| Attractive | Smiling |
| Black Hair | Male |
| Oval Face | High Cheekbones |

By considering different attribute pairs, we are able to generate datasets with different availabilities according to the same framework in Section 3.1.
However, unlike the controllable experiments, here we cannot generalize to unseen availability if we directly encode the availability as a one-hot vector indicating the attribute pairs.
Instead, as mentioned in Section 4, we compute the availability as the average distances of the samples’ embeddings to their labels or attributes clustering center, respectively.
Specifically, we first obtain the samples embeddings $\{z_{i}\}_{i=1}^{n_{tr}}$ from the used backbone (either ResNet18 or CLIP) and then compute the clustering center of each label and attribute as $\bm{\mu}_{y}$ and $\bm{\mu}_{a}$.
The availability $r$ is then:

$$ $\displaystyle r$ $\displaystyle=\frac{\sum_{y}d_{y}}{\sum_{a}d_{a}}$ (4) $\displaystyle d_{y}$ $\displaystyle=||z_{i}-\bm{\mu}_{y}||_{2}$ $\displaystyle d_{a}$ $\displaystyle=||z_{i}-\bm{\mu}_{a}||_{2}$ $\displaystyle\bm{\mu}_{y}$ $\displaystyle=\frac{1}{|y_{i}=y|}\sum_{y_{i}=y}z_{i}$ $\displaystyle\bm{\mu}_{a}$ $\displaystyle=\frac{1}{|a_{i}=a|}\sum_{a_{i}=a}z_{i}$ $$

This definition is intuitively similar to what is defined for availability in controllable experiments, where we had $r=\sigma_{c}^{2}/\sigma_{a}^{2}$.
Intuitively, a smaller average distance w.r.t. attribute labels signifies an easier spurious feature and therefore, higher availability.
This allows for training on datasets with diverse availabilities (constructed by different attribute pairs) and generalizes to unseen availabilities (e.g. on the COCO datasets).

### D.2 Detailed Experimental Setup

We provide the detailed experimental setup for the realistic experiments in Section 4.

#### Dataset of datasets.

In total, we created 1,320 datasets from CelebA (Liu et al., ), see Table 9 for the statistics for these datasets.
Specifically, we generate the training sets of the datasets with the combinations of values in Table 9, and for the degrees of distribution shifts, we consider 2 cases: (1) 3 shifts (spurious correlation, covariate shift and label shift) all present each in different degrees, we uniformly sampled 30 different triple degrees, and (3) there is only 1 shift present, in this case for each shift we 9 different values shown in the table (therefore in total $3*9-2=25$ different triple degrees).
We generate their test sets with the half number of samples as its training set for each dataset, but keep the number of samples the same for all groups (therefore balanced test sets with all $d_{(\cdot)}=0.5$).
We randomly split these datasets into 4:1 as the dataset of datasets for training the algorithm selector, and the unseen datasets for evaluation.
Additionally, we create 47 datasets from COCO (Lin et al., ) for evaluation, where we follow a similar generation strategy.
However, we were only able to generate a limited number of datasets since the cat, dog and indoor, outdoor are limited.
A future evaluation on datasets that support generating a larger number of datasets is expected.

**Table 9: Statistics for the dataset of datasets in realistic experiments.**
| Statistics | Value |
| --- | --- |
| Size of training set | {200, 500, 1000, 2000, 5000, 10000} |
| Input dimensionality | N/A |
| Availability | 4 different attribute pairs, see Table 8 |
| 3 shifts | uniformly sampled 30 feasible degrees (Figure 6) |
| 1 shift | {0.01, 0.05, 0.1, 0.3, 0.5, 0.7, 0.9, 0.95, 0.99} |

#### Algorithm selector.

In all formulations of the algorithm selector mentioned in Section 3.2, we use 4-layer MLPs to parameterize the algorithm selector, because we found a shallower or simpler model underfits (see Table 4) while a deeper model does not provide more improvements.

#### OOD tasks.

To solve the OOD tasks defined by each dataset in the dataset of datasets, we either do (1) linear probing on ResNet18 or CLIP (ViT-B/32) or (2) fine-tuning ResNet18.
In the first case (all tables except for Table 6), we use Adam optimizer with default hyperparameters, along with l2 regularization. We train for 1000 epochs to ensure convergence.
In the second case (Table 6), we use SubpopBench (Yang et al., ) and its default hyperparameters to fine-tune ResNet18. We use basic data augmentations (resize, crop, …).

## Appendix E Algorithm Selection with Estimated Dataset Descriptors

Here we study the scenarios where the information to compute dataset descriptors, such as the attribute for each sample (Liu et al., ), is not easily obtained at test time.
Recent works (Liu et al., ; Kirichenko et al., ; Qiu et al., ; Lee et al., ; Pagliardini et al., ) for OOD generalization aim to eliminate the need for attribute annotation by either: (1) infer the attribute annotation and then use them to run algorithms that require attribute annotation, (2) run ERM on the training set assuming that the ERM learns the spurious feature, and then build invariant classifier on top of the ERM classifier (e.g. fit a model that disagrees with the ERM).

We leverage the above first line of research, i.e. inferring the attribute annotation and use them to compute the dataset descriptors on the target training set.
Then, we can use OOD-Chameleon to select the suitable algorithms.
We infer the attributes by clustering the embeddings from frozen backbones, following Sohoni et al. (); You et al. ().
The intuition is that different attributes, such as cows in grass or desert, can be considered as ’subclasses’ or ’hidden stratifications’, and they are observed to be separable in the feature space of the deep models.
Hence, for example we can infer which cow belongs to which environment, by clustering on the embeddings.
In particular, the training samples are passed through the backbone of the OOD task (i.e. ResNet18 or CLIP in our case), and get the embeddings.
For each semantic class, we cluster the corresponding samples with K-means and assign different attribute labels to different clusters.
This gives each sample its inferred attribute annotation.
We can then use these inferred attribute annotations to compute dataset descriptors, where they are used to compute the degree of spurious correlation $d_{\mathrm{sc}}$ and covariate shift $d_{\mathrm{cs}}$, as well as the availability of spurious features $r$, see Appendix D.1 on how we compute the availability.

With the inferred dataset descriptors, we use the algorithm selector to predict suitable algorithms.
In Tab 10, we show that the suitable algorithms are still predictable with estimated dataset descriptors.
Interestingly, while having performance drops in most cases, using estimated dataset descriptors boosts the performance on COCO with ResNet18.

**Table 10: OOD-Chameleon with inferred attribute labels (and dataset descriptors) on CelebA and COCO. 0-1 Accuracy (higher is better) is shown.**
| Methods | Attribute | CelebA | COCO |  |  |
| --- | --- | --- | --- | --- | --- |
| ResNet18 | CLIP (ViT-B/32) | ResNet18 | CLIP (ViT-B/32) |  |  |
| Oracle Selection | N/A | 100 | 100 | 100 | 100 |
| Regression | ✓ | 75.4 ±1.5 | 72.9 ±1.1 | 51.1 ±1.0 | 68.8 ±0.6 |
| MLC | ✓ | 69.1 ±2.1 | 80.6 ±0.4 | 55.3 ±0.7 | 74.4 ±1.1 |
| PPL | ✓ | 80.0 ±1.1 | 83.7 ±0.6 | 65.9 ±0.5 | 75.8 ±0.5 |
| Regression | ✗ | 70.8 ±1.6 | 66.3 ±1.4 | 55.3 ±0.8 | 61.9 ±1.0 |
| MLC | ✗ | 68.2 ±0.7 | 72.0 ±1.1 | 61.7 ±1.2 | 70.2 ±0.9 |
| PPL | ✗ | 76.5 ±0.8 | 81.8 ±1.0 | 71.2 ±1.6 | 70.4 ±0.5 |

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 3
presentation: 1
questions: 1. In this paper, distribution shifts are categorized into three categories. However, any distribution shift can be decomposed into covariate shift and concept shift. Why is label shift required when shift on $P(X)$ and $P(Y|X)$ both exist? 
2. In Line 132, "A shift of spurious correlations implies a variation of an attribute/label co-occurrences, which means a shift on $P(Y|A)$ but not $P(Y|X_c)$." Previously the spurious correlation is stated as shift of $P(Y|X)$. However, if $X_c$ is a subset of variables of $X$, and if there is no shift on $P(Y|X_c)$, there should not be shift on $P(Y|X)$ since $P(Y|X)=P(Y|X_c)$. 
3. In Equation 2, why is the positive correlation between $y$ and $a$ considered as spurious correlation, while the negative correlation is not considered? In other words, when $d_{sc}$ is close to 1 or close to 0, both circumstances could imply strong spurious correlations.
soundness: 1
strengths: The problem setting is novel.
summary: Authors formulate a new problem setting of predicting the performances of multiple algorithms on a given dataset without training models. They propose a framework called OOD-CHAMELEON to address this setting.
weaknesses: 1. The practice of predicting performance with only some simple characteristics of the dataset and an algorithm represented by a one-hot vector does not really make sense to me. Given a learning algorithm and a dataset, there are too many other factors that could largely influence the final trained model, including hyperparameters. However, all other factors are ignored in this setting. 
2. Experiments are not sufficient enough to support the claims made in the paper.
   - Only five algorithms are selected as candidates while there are various OOD algorithms besides them. I believe at least several SOTA or influential algorithms could be added. 
   - Only two real-world datasets are included. 

3. The writing seems poor. 
   - The writing seems awkward in some places. 
     - In Line 018 "treats the task as a supervised classification"
     - In Line 025 "on unseen datasets of controllable and realistic image data". 
     - In Line 110, "It consists in predicting the best strategy to obtain a robust model given a statistical descriptor of the dataset." Here "consist in". 
   - The writing seems imprecise/ambiguous in some places. 
     - In Line 052 "A well-known study by Gulrajani & Lopez-Paz (2020) showed that none of these methods surpasses an ERM baseline across a collection of datasets." If here "these methods" refer to the upper line, then "the more complex ones" in Line 051 are not included since there are many new algorithms proposed in recent three years that are not included in the paper of DomainBed. 
     - In Line 075 "We posit that OOD generalization can be improved if we knew which algorithm to apply in each situation" why use "knew" instead of "know" here?  
     - In Line 105, "our findings call for improving OOD generalization by learning to better apply existing algorithms, instead of designing new ones." Here "instead of designing new ones" might be interpreted as designing new algorithms is less useful than learning to apply existing algorithms. 
   - The notations are not clear enough and some are abused. 
     - There are multiple confusions of variables and sets. For example, in Section 2.1, $X$ seems to be a random variable, however in $x\in X$, it seems to be the support set of the input variable. In Section 2.2, $\mathcal{A}(\cdot):D^{tr}\rightarrow h_{\theta}$, when defining a function mapping, it should be between two sets. However, here $D^{tr}$ is a dataset instead of the data space and $h_{\theta}$ is a detailed hypothesis instead of a hypothesis space. 
     - In Line 130, is $X_c$ a subset of variables of the input? This should be clarified. 
     - In Line 206, $|\mathcal{G}\_i|=n_{te}/i$. I suppose here $i$ is a wrong notation, which should be replaced by the number of groups.

---

confidence: 3
contribution: 1
initial_rating: 3
presentation: 3
questions: 1. How efficient is OOD-CHAMELEON in processing large-scale data sets? 
2. Are there any further optimization solutions to improve its efficiency in practical applications?
soundness: 2
strengths: Characterizing different OOD generalization tasks as distinct objectives and then selecting different methods to address those objectives is a reasonable approach. This strategy could have implications for the practical application of machine learning algorithms.
summary: The authors propose an approach to algorithm selection for OOD generalization by treating it as a supervised classification problem over candidate algorithms. They introduce OOD-CHAMELEON, a system that constructs a dataset of datasets representing various distribution shifts and trains a model to predict the relative performance of algorithms based on dataset characteristics. The experiments demonstrate that OOD-CHAMELEON can outperform individual algorithms and simple selection heuristics on unseen datasets with controlled and realistic image data. The paper also inspects the model to reveal non-trivial data/algorithm interactions and conditions under which one algorithm might surpass another, offering insights into the applicability of existing algorithms.
weaknesses: 1. The contributions of this paper seem insufficient to me. The three proposed methods are all based on existing simple techniques and don't provide genuinely new insights into algorithm selection for different OOD problems.
2. While using a learning-based approach for method selection is a promising idea, this paper doesn't delve into a crucial aspect: why this problem is learnable in the first place. There's no discussion about the differentiability or continuity of the problem of selecting the optimal algorithm for different datasets. To me, it's a good direction, but the solution likely isn't straightforward. It might require some specialized design and deeper insights to properly address the inherent challenges of learning algorithm selection.
3. Although the paper is complete in content, the layout of some parts is slightly compact, especially the algorithm description and experimental parts, which lack a clear modular structure. Some paragraphs are too long and the reading experience is poor. If the algorithm description, experimental design, and result analysis are divided into clearer sub-modules, the reading fluency may be improved.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 4
questions: - How would you construct a meta-dataset in cases where the shift is not obvious or when the attribute is not labeled in the datasets? 

- Does the coverage of the distribution over shifts impact results? For example, if the types of shifts are not equally represented in the meta-dataset or only some magnitudes of spurious correlation are represented.

- Would the space required to store the meta-dataset not get out of hand if you consider that a tunable model could have several entries with different values of one or several hyperparameters? Is there a way to mitigate this?
soundness: 3
strengths: - The possibility of learning how to select algorithms based on dataset characteristics is very interesting

- The motivation for the work is clear

- The performance of the method is good and makes the case for using properties of the data to select different algorithms on a per dataset  basis
summary: This work focuses on the development of a method for selecting algorithms, specifically with the goal of OOD generalization. Optimal selection of algorithms may depend on the type of shift which has occurred and what the algorithm is tailored to handle.


The proposed selection method, named OOD-chameleon, is a learnable method which aims to solve a classification task over a set of candidate algorithms.

The supervision of this task is proposed to be based on a meta-dataset which contains many datasets with different types of shifts and the candidate algorithms performances on these. The datasets are represented by dataset descriptors which contain measures of the distribution shift and data complexity.

These datasets are then constructed by sampling from synthetic distributions or from real-world datasets in the empirical evaluation of the method. The evaluation shows that the method selection performs better than just selecting the best performing model overall. Further, the authors show that leaving some dataset descriptors out of the meta dataset description can severely hamper the performance of the selected algorithm. This implies that certain information is more valuable when making a selection, depending on the algorithm characteristics.
weaknesses: - My main concern is the need to know the attributes that are shifting a priori. Finding the proposed metrics for different real-world datasets is not something straightforward. It is furthermore unclear how we would get at these metrics in general if they are not given. 

- The choice of attributes seem central for the approach to work at all. If the attributes used are not correlated to the shift it seems unlikely that the selection would be good for OOD generalization.

- Unclear why other baselines like Öztürk et al. cannot be compared to, would the comparison be unfair?

Typos and other comments:
Maybe add a line defining the performance $P_j$ on page 3

line 428: outperform
line 905: we 9

---

confidence: 3
contribution: 2
initial_rating: 3
presentation: 2
questions: Directly training multiple models and then aggregating their outputs might yield better results than the method proposed in this paper. In practical applications, what are the advantages of the method proposed in this paper compared to the ensemble model approach?
soundness: 2
strengths: 1) The approach improves the ability to generalize in OOD scenarios by selecting the most appropriate algorithm for a given dataset’s characteristics.
2) OOD-CHAMELEON eliminates the need for training and evaluating multiple models for algorithm selection, leading to a more efficient use of computational resources.
3) The method provides interesting insights into the conditions under which different algorithms are more suitable.
summary: This work introduces OOD-CHAMELEON, a method for selecting the most suitable learning algorithm for out-of-distribution (OOD) generalization challenges. By treating algorithm selection as a supervised classification problem, the proposed solution learns from a dataset of diverse shifts to predict the relative performance of algorithms based on a dataset’s characteristics. This allows for the a priori selection of the best learning strategy. Experimental results demonstrate that the adaptive selection approach outperforms individual algorithms and simple heuristics on unseen datasets with controllable and realistic image data, revealing some interactions between data and algorithms.
weaknesses: 1) The underlying concept of this article seems to require theoretical support. Selecting the most appropriate model based on data characteristics appears to be more challenging than learning a predictive model. To truly excel in this area, I believe a substantial number of datasets are needed for validation. However, in real-world scenarios, there may not be an abundance of datasets available. Therefore, further analysis and discussion are needed to determine the minimum number of datasets required to effectively choose the right model.
2) The experimental section of this paper uses a few datasets and models, which is insufficient to fully validate the method proposed in this paper and the insights provided.
3) The performance of a model also depends on how well it is optimized on the dataset. Please provide specific details on the training process for each model, particularly whether the model’s parameters have been optimized to their best possible values.

Meta-review: The overall quality is not good enough to make it an ICLR paper.

The authors should not complain all the three negative reviewers (rating 3) and say the only positive reviewer (rating 6) is the only one providing reasonable comments and suggestions, which is too aggressive and does not help anything in the end.

If I were a reviewer, I would think formalizing algorithm selection as supervised classification over candidate algorithms itself is problematic, since those algorithms are not designed to compete with each other just to win the selection, while single-label multi-class problems always have classes strongly competing with each other.

Decision: Reject