Why Diagnose the Shift Mechanism?
A classifier can perform differently after deployment for more than one reason. The class proportions may have changed while the feature distribution within each class stayed stable. The feature distribution may have changed while the relationship between features and labels stayed stable. Or the relationship itself may have changed. These mechanisms imply different corrections: a prior adjustment or importance weighting is justified only under its corresponding assumptions.
A labeled target audit sample—target observations for which the true class is recorded—allows direct checks of those assumptions. The central comparison is not merely whether the overall error rate changed. It is whether changes in features and errors within classes or meaningful feature regions agree with the proposed shift model.
These assumptions are not interchangeable. Under prior shift, class-conditional features are stable, but posteriors generally change because class priors changed. Under covariate shift, posteriors are stable, but class-conditional feature distributions can change as a consequence of the altered feature marginal. Thus, observing that \(P_t(X\mid Y)\) differs from \(P_s(X\mid Y)\) rules out prior shift, but does not by itself rule out covariate shift.
What Prior Shift Predicts for Posteriors
For a class \(k\), write \(\pi_{s,k}=P_s(Y=k)\) and \(\pi_{t,k}=P_t(Y=k)\). Under prior shift, Bayes' rule gives a precise prediction for the target posterior. For any \(x\) where the relevant conditional densities or mass functions are defined and the denominator is positive,
assuming \(\pi_{s,k}>0\) for every class whose target prior is positive. In words, prior adjustment multiplies each source posterior by the target-to-source prior ratio and then renormalizes. This is a prediction that can be checked against representative labeled target data; a changed posterior alone is not evidence against prior shift, because prior shift itself changes posteriors.
Proof. Let \(f_k(x)\) be a density or mass function for \(X\mid Y=k\), common to source and target by assumption. Bayes' rule under the target distribution gives
Under the source distribution, \(P_s(Y=k\mid X=x)=\pi_{s,k}f_k(x)/\sum_j\pi_{s,j}f_j(x)\). Multiplying this source posterior by \(\pi_{t,k}/\pi_{s,k}\) gives \(\pi_{t,k}f_k(x)/\sum_j\pi_{s,j}f_j(x)\). The common denominator across classes cancels when these adjusted values are normalized, leaving the target formula. \(\square\)
Worked Example: A Posterior Change Explained by Prior Shift
Let \(Y\) and a binary feature \(X\in\{A,B\}\) have source priors \(P_s(Y=1)=0.4\), \(P_s(Y=0)=0.6\), and class-conditional probabilities \(P_s(A\mid Y=1)=0.2\), \(P_s(A\mid Y=0)=0.8\). Suppose the target class-1 prior is \(0.7\), and the class-conditional feature probabilities are unchanged. Find the posterior probability of class 1 at \(A\) in each population.
In the source, the joint probabilities at \(A\) are \(P_s(Y=1,A)=0.4(0.2)=0.08\) and \(P_s(Y=0,A)=0.6(0.8)=0.48\). The second term uses \(P_s(Y=0)=0.6\). Therefore,
In the target, the corresponding joint probabilities are \(P_t(Y=1,A)=0.7(0.2)=0.14\) and \(P_t(Y=0,A)=0.3(0.8)=0.24\). Hence,
The posterior changed from \(1/7\) to \(7/19\), but the class-conditional probabilities of \(A\) did not change. The change is exactly what prior adjustment predicts; it is not, by itself, evidence of a conditional shift that invalidates prior correction.
Diagnosing the Assumptions With Labeled Audits
A useful audit separates checks by the assumption being tested. To assess prior shift, compare feature distributions within each class across source and target. For a feature region \(B\), compare \(P_s(X\in B\mid Y=k)\) with \(P_t(X\in B\mid Y=k)\). Differences beyond sampling variation are evidence against prior shift. The audit should also compare target posterior behavior with the prior-adjusted source predictions.
To assess covariate shift, compare conditional label behavior across populations at comparable feature values or regions. For example, within a region \(B\), compare \(P_s(Y=k\mid X\in B)\) with \(P_t(Y=k\mid X\in B)\). Because conditioning only on a coarse region can hide variation within that region, this is a diagnostic approximation rather than a universal test of equality at every \(x\). Calibration and proper-score diagnostics from earlier material can summarize prediction behavior, but an aggregate score alone cannot establish which shift mechanism holds.
Classification errors provide a complementary diagnostic. For a fixed rule \(h\), define its class-specific error as \(P(h(X)\ne Y\mid Y=k)\), and examine it in scientifically meaningful feature regions as well as overall. A changed error rate within a class or region may reveal that the classifier encounters different cases or that its conditional predictions no longer match the labels. Error patterns are evidence, not a unique identification of mechanism: a changed mixture of subgroups can alter aggregate error even when error behavior within each subgroup is stable.
Worked Example: Covariate Shift Can Change Class-Conditional Features
Let \(X\in\{A,B\}\), with source feature probabilities \(P_s(A)=P_s(B)=0.5\). Suppose the posterior is invariant across populations: \(P_s(Y=1\mid A)=P_t(Y=1\mid A)=0.1\) and \(P_s(Y=1\mid B)=P_t(Y=1\mid B)=0.6\). The target feature probabilities are \(P_t(A)=0.8\) and \(P_t(B)=0.2\). Verify that the class posterior is unchanged, while the class-conditional feature distribution changes.
The source class-1 prior is \(0.5(0.1)+0.5(0.6)=0.35\). Its joint probability for \(A,Y=1\) is \(0.5(0.1)=0.05\), so
The target class-1 prior is \(0.8(0.1)+0.2(0.6)=0.20\), and its joint probability for \(A,Y=1\) is \(0.8(0.1)=0.08\). Thus,
So \(P(X\mid Y=1)\) changed from \(1/7\) to \(0.4\), even though \(P(Y\mid X)\) is unchanged by construction. This is compatible with covariate shift, not prior shift. For the rule that predicts class 1 at \(B\) and class 0 at \(A\), the conditional error is \(0.1\) at \(A\) and \(0.4\) at \(B\). The source risk is \(0.5(0.1)+0.5(0.4)=0.25\); the target risk is \(0.8(0.1)+0.2(0.4)=0.16\). A risk change here comes from the feature mix, even though the posterior relationship is stable.
A Direct Within-Class Comparison
For a binary feature or a prespecified feature region, an audit can estimate class-conditional probabilities separately in source and target. If source and target samples are independent random samples within class \(k\), a two-proportion comparison quantifies whether an observed difference is larger than sampling variability. A class-stratified audit is especially useful for this purpose: it gives adequate observations in each class, though it does not reproduce the target population class proportions.
The following calculation illustrates evidence against prior shift. It does not establish that every aspect of the conditional distribution has changed; it tests the selected feature-region comparison.
Worked Example: Detecting a Class-Conditional Change
In source data, among 100 class-1 observations, 20 have \(X\in A\); among 100 class-0 observations, 80 have \(X\in A\). A labeled target audit contains 40 observations from each class: 20 of the class-1 observations and 32 of the class-0 observations have \(X\in A\). Compare the class-conditional proportions.
For class 1, the estimated source and target proportions are \(20/100=0.20\) and \(20/40=0.50\), a difference of \(0.30\). Under the null hypothesis of equal proportions, the pooled estimate is \(\hat p=(20+20)/(100+40)=2/7\). The usual large-sample standard error for the difference is
The standardized difference is \(0.30/0.0845\approx3.55\), a substantial discrepancy under the equal-proportions null in a two-sided large-sample test. For class 0, the proportions are \(80/100=0.80\) and \(32/40=0.80\), with no observed difference. The class-1 result is evidence against prior shift for this feature region: its class-conditional probability differs across populations. The class-0 result does not erase that evidence, and neither comparison alone characterizes all features.
Why Subgroup Error Patterns Matter
An overall error rate can conceal compensating changes. If errors rise in one feature region and fall in another, the aggregate may remain nearly constant. Conversely, the aggregate can change merely because the target contains different proportions of regions with different fixed error rates. A labeled audit therefore benefits from reporting error counts and rates by class and prespecified, relevant feature regions, alongside the aggregate.
A useful formal identity clarifies this point. Let \(G=g(X)\) be a fixed, measurable subgroup label and \(h\) a fixed classifier. When the probabilities are defined,
This follows by partitioning the error event over the disjoint events \(\{G=g,Y=k\}\). Thus aggregate risk depends both on subgroup/class frequencies and on conditional error rates. A changed aggregate does not identify which factor changed. In a class-stratified target audit, the sampling fractions across classes may have been chosen by design, so raw pooled error is not automatically the target-population risk; use appropriate target class proportions or design weights for that estimand.
Limits and Common Pitfalls
No finite audit can verify equality of entire conditional distributions from a few comparisons. The diagnostic depends on which features, regions, and posterior summaries are examined. Small target class counts give imprecise estimates; many unplanned comparisons inflate the chance of finding an apparent discrepancy. Prespecifying important comparisons, reporting uncertainty, and treating exploratory findings as exploratory help prevent overclaiming.
Support is also essential. If a target feature region has no source observations, source conditional behavior there cannot be checked or reliably transferred. Likewise, if the audit selectively samples cases in a way that depends on features within class, naive estimates of \(P_t(X\mid Y)\) may be biased unless the sampling design is accounted for. A diagnostic that appears to support an invariance assumption in an overlap region says nothing automatic about areas without overlap.
- Mistake: calling every posterior change evidence against prior shift. Prior shift changes posteriors when priors change. Compare observed target posteriors with the prior-adjusted source predictions.
- Mistake: treating a change in \(P(X\mid Y)\) as proof against covariate shift. Covariate shift requires stable \(P(Y\mid X)\), not stable class-conditional feature distributions.
- Mistake: trusting an unchanged overall error rate. Different subgroup changes can cancel. Inspect conditional patterns and uncertainty, not only the aggregate.
- Mistake: interpreting a noisy audit discrepancy as a mechanism. Sampling variability, multiplicity, selection, and limited overlap can all produce misleading comparisons.
Check Your Understanding
Use the definitions and calculations above to answer these questions.
- Under prior shift, which conditional distribution must remain invariant, and why can the posterior still change?
- Under covariate shift, can \(P(X\mid Y)\) change? Explain briefly.
- A target audit finds a larger class-1 error rate in one feature region but the same overall error as the source. Give one explanation for this pattern.
- Why can a class-stratified target audit estimate class-conditional feature probabilities but fail to estimate the target's unweighted overall error directly?
- What limitation arises if an important target feature region has no corresponding source observations?