Skip to content
AI.info

Advanced techniques

Domain Adaptation and Domain Generalization

Learn the difference between adapting to an observed target domain and generalizing to domains unavailable during training.

By the end you can

The word “domain” hides several different changes

A domain may be a hospital, a camera, a country, a time period, a device, a language variety, or a customer segment. Two domains can differ in input frequencies, label prevalence, measurement quality, or in the relationship between inputs and outcomes. Those are four different problems, and they need four different responses.

Domain adaptation assumes some access to the target domain during development — unlabeled target examples, a small labeled sample, or both. Domain generalization asks for performance on domains not available during training. The second is harder to validate, because the true deployment shift is only partially observable.

No algorithm can recover information that the target inputs do not contain. None can reliably extrapolate far beyond training support. So before aligning representations, check two things: that the target task is still well defined, and that source and target share enough structure for transfer to mean anything.

Distribution shift is a family of problems; naming the type of shift is part of the solution.

Comparison

Different shifts, different assumptions

These categories are idealizations, but they prevent careless use of a single adaptation recipe.

Google Flu Trends is the documented case of the third column. Writing in Science in 2014, Lazer and three colleagues reported that “GFT also missed by a very large margin in the 2011-2012 flu season and has missed high for 100 out of 108 weeks starting with August 2011”. Their diagnosis was not that the searching population had moved. It was “algorithm dynamics”. Google’s own search algorithm kept changing underneath the model — 86 changes in June and July 2012 alone, by the count reported on the official Google search blog. The relationship between a query and an influenza-like illness moved while the fitted model held it fixed. That is concept shift. No reweighting of input frequencies repairs it.

The scale of the failure was confirmed independently. Olson and four co-authors reassessed the system in PLOS Computational Biology in 2013: “We identified substantial flaws in the original and updated GFT models at all three geographic scales, including completely missing the first wave of the 2009 influenza A/H1N1 pandemic, and greatly overestimating the intensity of the A/H3N2 epidemic during the 2012/2013 season.” Missing high for 100 of 108 weeks, and missing a pandemic wave, is what “common after policy or behavior changes” looks like when the behavior belongs to the platform rather than to the patients.

FigureComparison · 3 columns

Covariate shift

Input frequencies change while the conditional label relationship is assumed stable.

  • May support importance weighting
  • Requires overlap between source and target inputs
  • Common in changing populations
  • Assumption must be tested indirectly

Label shift

Class prevalence changes while class-conditional input distributions are assumed stable.

  • Can motivate prior correction
  • Needs reasonably stable class signatures
  • Calibration matters
  • Common in screening contexts

Concept shift

The relationship between inputs and labels changes.

  • Old decision boundaries may be wrong
  • Feature alignment alone is insufficient
  • Usually needs fresh labels or redesign
  • Common after policy or behavior changes

Visual

Adaptation versus generalization

How much target-domain evidence a team can get changes what it can select and validate.

The Epic Sepsis Model is what happens when a model is tuned and reported on its developer’s domains and then meets someone else’s. It was deployed at hundreds of US hospitals on a developer-reported AUC of 0.76-0.83. Then an outside team validated it at Michigan Medicine: 27,697 patients and 38,455 hospitalizations, between 6 December 2018 and 20 October 2019. There the model scored an AUC of 0.63 (95% CI 0.62-0.64). At the score threshold of 6 it reached 33% sensitivity, 83% specificity and 12% positive predictive value. It missed 1,709 of the 2,552 sepsis cases — 67% of them — while alerting on 18% of all hospitalizations. Wong and colleagues put the conclusion in the Key Points of their 2021 paper in JAMA Internal Medicine, and did not hedge it: “This study suggests that the Epic Sepsis Model poorly predicts sepsis; its widespread adoption despite poor performance raises fundamental concerns about sepsis management on a national level.”

The result was not a quirk of one hospital system. A different group ran the same model over 145,885 emergency-department encounters at two Texas county hospitals, Ben Taub and Lyndon B Johnson, during 2023. Sensitivity 14.7%. Specificity 95.3%. Positive predictive value 7.6%. They report those numbers as aligning with previously published external validations, and as slightly worse than Epic’s own published analysis. An AUC of 0.63 at Michigan Medicine against a developer-reported 0.76 to 0.83 is the distance between the developer’s domains and someone else’s. Nothing in the developer’s own evaluation could have shown it.

Measuring that difficulty at scale is what DomainBed is for. Gulrajani and Lopez-Paz built it out of seven multi-domain datasets, nine baseline algorithms and three model-selection criteria, precisely because “model selection is non-trivial for domain generalization tasks”. What came back was awkward: “when carefully implemented, empirical risk minimization shows state-of-the-art performance across all datasets”.

FigureLayers · 3 layers
  1. 01

    Source-only baseline

    Train on observed source domains with ordinary empirical risk minimization.

  2. 02

    Domain adaptation

    Use target-domain data during development, with or without target labels.

  3. 03

    Domain generalization

    Select methods using source domains and test on an unseen domain.

Model selection is much harder when the deployment domain is genuinely unseen.

Key idea

Domain invariance can delete signal

A representation that hides domain identity is useful only if the removed information is nuisance variation. Sometimes the domain is entangled with genuine predictive structure. Medical prevalence, sensor calibration, and treatment practice all differ across hospitals. Forcing perfect alignment may blur distinctions needed for accurate or fair decisions.

Evaluate both transfer gain and information loss. Inspect class-conditional behavior, calibration, and target slices rather than relying only on a global domain-confusion score.

This is not only a practical worry. There is a proof. Zhao and three colleagues showed in 2019 that any method learning invariant representations runs into an information-theoretic lower bound on its joint error, and they built a counterexample with conditional shift to show it bites. The bound names “a fundamental tradeoff between learning invariant representations and achieving small joint error on both domains when the marginal label distributions differ from source to target”. Marginal label distributions differ across domains all the time; that is the ordinary case in screening and in medicine. Where they differ, perfect alignment is not a free improvement. It is a purchase made with accuracy.

Invariant is not synonymous with useful; the model should discard nuisance variation, not target-relevant evidence.

Example

Common intervention families

Each method encodes a different belief about what should remain stable across domains.

  • Reweighting: Give source examples more influence when they resemble the target distribution.
  • Feature alignment: Encourage source and target representations to have similar distributions.
  • Domain-adversarial training: Learn features useful for the task but less predictive of domain identity.
  • Data augmentation and style randomization: Create plausible domain variation during source training.
  • Small target calibration set: Adapt thresholds, normalization, or a lightweight head with direct target evidence.
  • Robust baseline and model selection: Compare specialized methods against carefully tuned empirical risk minimization, which across DomainBed's seven datasets, nine algorithms and three selection criteria was the state of the art.

Steps

A validation design for domain shift

The split design should reflect the shift you claim to handle.

Start with what a domain-held-out split costs, because it can be measured exactly. CAMELYON17 collects 1,000 whole-slide lymph-node images — 5 slides each from 100 training and 100 test patients. Its organisers state on the challenge’s Data page that “The data set for CAMELYON17 is collected from 5 medical centres in the Netherlands.” Koh, Sagawa and their co-authors turned that sentence into a split for the WILDS benchmark. The domain is “which of 5 hospitals the patch was from”, and “The training and test sets comprise class-balanced patches from separate hospitals”. The same tumour classifier, trained with ordinary empirical risk minimization, reads 93.2% (SD 5.2) average accuracy when the test patches come from the training hospitals. It reads 70.3% (SD 6.4) when the hospital is one it has never seen. A gap of 22.9 percentage points, produced by nothing but the choice of split. Across all 10 datasets in the benchmark the authors report that “standard training yields substantially lower out-of-distribution than in-distribution performance”, and that “This gap remains even with models trained by existing methods for tackling distribution shifts”.

Step 3 is where most published work stops short. A 2019 review in the Korean Journal of Radiology screened 2,748 medical-imaging AI papers published between January and August 2018 and kept the 516 that reported algorithm performance. Of those, “6% (31 of 516) of the studies performed external validation”. Not one of the 31 combined all three recommended design features: diagnostic cohort design, multiple institutions, and prospective data collection. The U.S. Government Accountability Office and the National Academy of Medicine repeated the count in a 2022 technology assessment: “A review of 516 studies that evaluated the performance of image-based AI algorithms found only 6 percent of the studies performed external validation against data sets from institutions or time periods that differed from the training data.” A 22.9-point gap is invisible by construction to every study outside that six percent.

Step 6 exists because a reported gap is itself an estimate, and estimates have builders. In 2019 Recht and three colleagues rebuilt the CIFAR-10 and ImageNet test sets by re-running the original collection process. Their finding: “We evaluate a broad range of models and find accuracy drops of 3% - 15% on CIFAR-10 and 11% - 14% on ImageNet”. Then Engstrom and five colleagues remeasured the human selection frequencies that the rebuilding had relied on. “We show that after remeasuring selection frequencies and correcting for statistical bias, only an estimated 3.6% of the original 11.7% accuracy drop remains unaccounted for.” Most of that celebrated shift was in the instrument, not in the world. Report the uncertainty and the construction of the split alongside the number. Otherwise the number will be read as evidence of a shift that may not exist.

FigureProcess · 6 steps
  1. 1. Enumerate domains

    Define units such as sites, devices, time periods, or regions.

  2. 2. Separate adaptation evidence

    Document which target examples and labels are available during development.

  3. 3. Use domain-held-out evaluation

    Hold out entire domains or future windows rather than random rows.

  4. 4. Tune without peeking

    Keep the final target domain outside hyperparameter and method selection.

  5. 5. Compare robust baselines

    Include well-tuned source-only training and simple target calibration.

  6. 6. Report per-domain uncertainty

    Show variability, worst-domain behavior, and support gaps.

Analogy

The recipe tested in several kitchens

In three kitchens with three different ovens, the same recipe comes out three ways. Domain adaptation is like visiting the target kitchen, measuring its temperature, and adjusting the recipe. Domain generalization is like preparing for a fourth kitchen you have never seen, by testing the recipe under varied conditions.

But a fourth kitchen that lacks an essential ingredient, or that means something else by the name of the dish, is not an oven problem. Oven calibration cannot repair a changed target concept. That is why re-tuning Google Flu Trends on the last season’s queries never fixed it.

Robustness to nuisance variation is possible; robustness to an undefined or changed task requires new evidence.

Steps

Maintain a shift register, not a single drift score

A domain shift should be documented as a set of hypotheses that can be tested and revised.

This is not merely a recommended habit. For one class of products a regulator already requires it in writing, before the model is allowed to change. On 4 December 2024 the FDA announced in the Federal Register its final guidance on predetermined change control plans for artificial intelligence-enabled device software functions, issued under section 515C of the Federal Food, Drug, and Cosmetic Act. A manufacturer may pre-authorise future model modifications only by filing a plan that will “describe the planned AI-DSF modifications, the associated methodology to develop, validate, and implement those modifications, and an assessment of the impact of those modifications”.

That is steps 3, 5 and 6 of the register, stated as a condition of marketing: what target evidence exists, how each adaptation will be validated, and what its consequences would be. All of it committed to before the first update ships, rather than reconstructed after a deployment goes wrong.

FigureProcess · 6 steps
  1. 1. Describe the boundary

    Name the site, device, time window, language, or policy that defines each domain.

  2. 2. Classify the suspected shift

    Separate input-frequency, prevalence, measurement, and concept changes.

  3. 3. Record target evidence

    State which unlabeled examples, labels, or deployment feedback are available.

  4. 4. Test overlap

    Identify regions where the target lacks source support or uses unseen categories.

  5. 5. Track adaptation side effects

    Measure calibration, class-conditional behavior, and performance on original domains.

  6. 6. Define rollback conditions

    Stop adaptation when confidence collapses, labels disagree, or target quality cannot be verified.

Key takeaways