Beyond Invariance: Test-Time Label-Shift Adaptation for Distributions with "Spurious" Correlations

Qingyao Sun, Kevin Murphy, Sayna Ebrahimi, Alexander D'Amour · OpenReview

Abstract

Changes in the data distribution at test time can have deleterious effects on the performance of predictive models $p(y|x)$. We consider situations where there are additional meta-data labels (such as group labels), denoted by $z$, that can account for such changes in the distribution. In particular, we assume that the prior distribution $p(y, z)$, which models the dependence between the class label $y$ and the "nuisance" factors $z$, may change across domains, either due to a change in the correlation between these terms, or a change in one of their marginals. However, we assume that the generative model for features $p(x|y, z)$ is invariant across domains. We note that this corresponds to an expanded version of the widely used "label shift" assumption, where the labels now also include the nuisance factors $z$. Based on this observation, we propose a test-time label shift correction that adapts to changes in the joint distribution $p(y, z)$ using EM applied to unlabeled samples from the target domain distribution, $p_t(x)$. Importantly, we are able to avoid fitting a generative model $p(x|y,z)$, and merely need to reweight the outputs of a discriminative model $p_s(y,z|x)$ trained on the source distribution. We evaluate our method, which we call "Test-Time Label-Shift Adaptation" (TTLSA), on several standard image and text datasets, as well as the CheXpert chest X-ray dataset, and show that it improves performance over methods that target invariance to changes in the distribution, as well as baseline empirical risk minimization methods.

Introduction

Machine learning models are notoriously sensitive to distribution shifts. A common failure mode involves "spurious correlations," where a model learns to rely on nuisance features (like background color or patient demographics) that correlate with the target label in the training set but change in the real world.

The dominant research trend has been Domain Generalization, which seeks to build models that are "invariant"—meaning they ignore nuisance features entirely. However, this paper argues that nuisance features often provide valuable prior information. If you know you are in a specific environment, the probability of certain labels increases. By forcing invariance, models throw away this useful context. Instead, the authors propose adapting to these correlations at test time.

The TTLSA Framework

The proposed method, Test-Time Label-Shift Adaptation (TTLSA), relies on an expanded version of the label shift assumption. While standard label shift assumes the probability of features given a label, $p(x|y)$, is invariant, TTLSA assumes that $p(x|y, z)$ is invariant, where $z$ represents nuisance factors or metadata.

Causal graph representing the expanded label shift assumption where $U$ is a latent variable influencing both label $y$ and nuisance factor $z$, which together generate features $x$.

TTLSA operates in three stages:

  1. Source Training: A model is trained to predict a "meta-label" $m = (y, z)$. To ensure the model's confidence is reliable for adaptation, Bias Corrected Temperature Scaling (BCTS) is applied for calibration.
  2. Test-Time Adaptation: When encountering a new, unlabeled target domain, the model uses an Expectation-Maximization (EM) algorithm to estimate the new joint prior $p_t(y, z)$ based on the distribution of features $x$.
  3. Reweighting: The model’s source predictions are reweighted using the new estimated prior, allowing it to use spurious features optimally for the specific environment it is currently in.

Experimental Results

The researchers evaluated TTLSA across diverse tasks, including Colored MNIST (synthetic) and CheXpert (real-world medical X-rays).

AUC performance on Colored MNIST (a) and CheXpert (b) across varying shift parameters. TTLSA demonstrates a characteristic U-shaped performance curve in (a) and superior stability in (b).

Key findings include:

  • Invariance vs. Adaptation: Invariant models typically show flat performance across correlation shifts. In contrast, TTLSA produces a U-shaped performance curve on Colored MNIST, matching invariant models at zero correlation but significantly outperforming them as target domain correlations increase.
  • Superior Accuracy: On the CheXpert dataset, TTLSA significantly outperformed both standard Empirical Risk Minimization (ERM) and invariant baselines.
  • Calibration is Essential: The EM algorithm relies on accurate model confidence. Without explicit calibration (BCTS), the adaptation process can degrade performance.

Conclusion

TTLSA reframes spurious correlations from "biases to be removed" into "prior information to be updated." By embracing these features rather than ignoring them, models can achieve higher accuracy across shifting domains. A primary limitation is the requirement for nuisance labels ($z$) during training, suggesting future work in unsupervised estimation of these factors to broaden the method's applicability.

Summary updated

BibTeX
@inproceedings{sun2023beyond,
  author = {Qingyao Sun and Kevin Murphy and Sayna Ebrahimi and Alexander D'Amour},
  title = {{Beyond Invariance: Test-Time Label-Shift Adaptation for Distributions with "Spurious" Correlations}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=9mJXDcr17V},
}
Figure