Deployment of Image Analysis Algorithms under Prevalence Shifts

Patrick Godau, Piotr Kalinowski, Evangelia Christodoulou, Annika Reinke, Minu Tizabi, Luciana Ferrer, Paul Jäger, Lena Maier-Hein

TL;DR

When medical machine learning models are deployed in the real world, they often encounter a "prevalence shift"—a change in the frequency of diseases compared to the training data. This paper demonstrates that ignoring this shift severely breaks model calibration, leads to suboptimal decision thresholds, and distorts validation metrics. To fix this, the authors introduce a simple, post-hoc workflow that uses estimated deployment prevalences to adapt models without requiring any new annotated data.

What Problem Does This Paper Address?

Imagine developing an AI model to detect a rare skin cancer. To train it effectively, you build a balanced dataset: 50% benign and 50% malignant cases. However, when deployed in a general clinic, the actual prevalence of that cancer might be less than 1%. This discrepancy is known as a prevalence shift (or label shift).

While the machine learning community heavily researches architectural tweaks and domain adaptation, the specific operational impact of prevalence shifts is largely ignored in practice. The authors reviewed 53 recent medical imaging papers and found that almost none accounted for re-calibration or adjusted decision rules post-deployment.

This paper systematically exposes three critical failures caused by ignoring prevalence shifts:

  1. Miscalibration: A model's predicted probabilities (e.g., "99% chance of malignancy") become highly inaccurate.
  2. Suboptimal Decision Rules: The default strategy of choosing the highest score (argmax) or using a threshold tuned on training data no longer yields optimal clinical decisions.
  3. Misleading Performance Metrics: Common metrics like Accuracy, F1-score, and Matthews Correlation Coefficient (MCC) change drastically based on class frequencies, meaning a model's validation score tells you very little about how it will perform in the wild.
Fig. 1: Summary of contributions. (a) Based on a dataset comprising 30 medical image classification tasks, we show that prevalence shifts between development data and deployment data engender various problems. (b) Our workflow for prevalence-aware medical image classification addresses all of these issues.

Methods

The authors propose a comprehensive, 5-step prevalence-aware image classification workflow designed to adjust any trained "black-box" model before deployment:

  1. Estimate Deployment Prevalences: Obtain an estimate of the disease base rates in the target environment using epidemiological data or medical records. This assumes an anticausal relationship (i.e., the disease category causes the visual manifestation in the image).
  2. Prevalence-Aware Re-Calibration: Standard temperature scaling only adjusts model confidence uniformly. The authors instead use affine scaling ($f(x) = x/t + b$), adding a bias term ($b$) to shift thresholds. Crucially, they optimize this scaling using a weighted cross-entropy loss, where the weights correspond to the ratio of deployment prevalence to development prevalence.
  3. Configure Validation Metrics: Instead of relying on prevalence-dependent metrics like F1-score, they advocate for Expected Cost (EC). EC incorporates the estimated deployment prevalences and allows clinicians to assign specific "costs" to different errors (e.g., the cost of a false negative vs. a false positive).
  4. Set Prevalence-Aware Decision Rules: Rather than blindly using argmax, the decision threshold is mathematically optimized to minimize the Expected Cost based on the newly calibrated probabilities.
  5. External Validation: Continuous monitoring on actual deployment data to ensure safety.

Datasets

To ensure their findings were robust, the authors evaluated their workflow across a massive benchmark of 30 distinct medical image classification tasks.

Fig. 2: Medical image classification tasks used in this study. The number of samples (red) and classes (green) ranges from 1,200 to 121,583 and two to eight, respectively. The imbalance ratio (blue) varies between 1 and 10.9.

These tasks spanned:

  • Multiple Modalities: X-ray, MRI, laparoscopy, gastroscopy/colonoscopy, fundus photography, capsule endoscopy, and microscopy.
  • Dataset Sizes: Ranging from 1,200 to over 121,583 samples.
  • Imbalance Ratios: Ranging from perfectly balanced (1.0) to highly imbalanced (10.9).

Key Insights and Ideas

  • Temperature Scaling is Not Enough: The deep learning community frequently relies on temperature scaling for calibration. The authors show this fails under prevalence shifts because it cannot shift the decision boundaries—it only alters the sharpness of the probabilities. Affine scaling with prevalence-driven weights is mandatory.
  • Tuned Thresholds Don't Generalize: If you tune a classification threshold (e.g., choosing 0.35 instead of 0.5 to maximize F1-score) on your validation set, that threshold completely falls apart when the underlying disease prevalence changes.
  • The Illusion of Performance: Standard metrics like Accuracy and F1-score fluctuate wildly purely due to the shift in class distribution, masking the actual capability of the model. Expected Cost provides a stable, mathematically sound alternative.

Key Results

The experiments simulated deployment environments with varying Imbalance Ratios (IR) from 1 to 10.

  • Calibration Fix: Without adjustment, the Class-Wise Calibration Error (CWCE) spiked as the prevalence shift widened. The proposed weighted affine scaling kept the calibration error consistently near zero across all 30 tasks.
  • Better Clinical Decisions: Implementing the prevalence-aware workflow led to an average relative decrease of 25% in Expected Cost compared to the unadjusted baseline model.
  • Metric Stability: While standard metrics showed massive, deceptive deviations between development and deployment (up to 0.41 for Accuracy and 0.46 for F1-score), the prevalence-adjusted Expected Cost accurately reflected true performance. Furthermore, sensitivity analyses proved the workflow remains highly effective even if the deployment prevalence estimates are slightly inaccurate.
Fig. 4: Effect of prevalence shifts on the decision rule. The difference between the actual metric score and the optimal metric score (optimal decision rule) is shown as a function of the imbalance ratio for non-re-calibrated (left) and re-calibrated (right) models for two decision rule strategies: argmax (top) and threshold optimization on the development test set (bottom). Mean (lines) and standard deviation (transparent area) obtained from n=24 binary tasks.

Limitations and Future Work

The primary limitation of this workflow is its reliance on the anticausal assumption (that the label $Y$ causes the image features $X$). While this holds true for many medical diagnoses (e.g., a tumor causes a shadow on an X-ray), it does not account for covariate shifts, such as changes in image acquisition protocols, different scanner models, or varying patient demographics.

Future work will need to explore how to elegantly combine this prevalence-adjustment framework with methods designed to tackle acquisition-driven domain gaps.

Summary updated

BibTeX
@inproceedings{godau2023deployment,
  author = {Patrick Godau and Piotr Kalinowski and Evangelia Christodoulou and Annika Reinke and Minu Tizabi and Luciana Ferrer and Paul Jäger and Lena Maier-Hein},
  title = {{Deployment of Image Analysis Algorithms under Prevalence Shifts}},
  booktitle = {International Conference on Medical Image Computing and Computer-Assisted Intervention},
  year = {2023},
  url = {https://openreview.net/forum?id=BoBXvVDkm5_},
}
Figure