Tutorials › Statistical Learning (Graduate) › Worked Risk Transfer Under Multiple Shift Assumptions

Robustness and Distribution Shift · Tutorial 988 of 989

Worked Risk Transfer Under Multiple Shift Assumptions

Work through one binary prediction problem under competing shift assumptions, then see how a robust risk and uncertainty assessment depend on the assumptions retained.

Advanced 10 min read

What You'll Learn

  • Calculate a covariate-weighted risk from source errors and a target covariate distribution.
  • Estimate a target class prevalence from unlabeled covariates under label shift.
  • Compute the corresponding label-shift-corrected risk from class-conditional errors.
  • Form a worst-case risk over competing shift models and an uncertainty set.
  • Separate sampling uncertainty from uncertainty about the shift mechanism.

One Prediction Problem, Several Transfer Assumptions

A risk estimate for a target population is not determined by source labels and unlabeled target covariates alone. It also depends on what relationship between source and target distributions is assumed. In this tutorial, a fixed binary classifier is evaluated using three calculations: covariate-shift weighting, label-shift correction, and a robust worst case over both models. The point is not that one estimate is automatically preferable, but that each estimate answers a different conditional question.

Let \(X\) be a binary covariate with values \(a\) and \(b\), and let \(Y\in\{0,1\}\) be the label. A fixed classifier \(g\) predicts a label from \(X\). We use the zero-one loss \(\ell(g(X),Y)=\mathbf{1}\{g(X)\ne Y\}\), so the target risk is \(R_T=E_T[\ell(g(X),Y)]\). The source distribution \(P_S\) supplies labeled observations; the target distribution \(P_T\) supplies covariate observations but no labels.

Definition: Covariate shift assumes \(P_T(Y\mid X)=P_S(Y\mid X)\), with target covariate values supported wherever source covariate values occur. Label shift assumes \(P_T(X\mid Y)=P_S(X\mid Y)\), while allowing the class prevalence \(P_T(Y=1)\) to differ from \(P_S(Y=1)\). These are distinct assumptions; neither follows merely from observing target covariates.

The Source Data and Target Covariates

Suppose the source sample has 1,000 observations, summarized by the following counts. The classifier predicts 0 when \(X=a\), and 1 when \(X=b\). Thus errors occur in the \(Y=1,X=a\) cell and the \(Y=0,X=b\) cell.

\(X=a\)\(X=b\)Total
\(Y=1\)300100400
\(Y=0\)200400600
Total5005001,000

The source risk is \((300+400)/1000=0.70\). The source covariate probabilities are \(P_S(X=a)=P_S(X=b)=0.5\). The conditional error probabilities, estimated here by the corresponding source proportions, are \(e_a=P_S(\ell=1\mid X=a)=300/500=0.6\) and \(e_b=P_S(\ell=1\mid X=b)=400/500=0.8\). The target sample has 100 covariate observations: 70 are \(a\) and 30 are \(b\). Its empirical covariate proportions are therefore 0.7 and 0.3.

Worked Example: Covariate-Weighted Risk

Under covariate shift, the conditional error rates remain \(e_a=0.6\) and \(e_b=0.8\), while the target covariate proportions replace the source proportions. The target risk estimate is

$$ \hat R_{\mathrm{cov}} =0.7(0.6)+0.3(0.8) =0.42+0.24 =0.66. $$

The same calculation can be expressed as source importance weighting. The empirical density ratios are \(0.7/0.5=1.4\) for \(a\) and \(0.3/0.5=0.6\) for \(b\). The source error mass at \(a\) is \(300/1000=0.3\), and at \(b\) it is \(400/1000=0.4\). Weighting these contributions gives

$$ \hat R_{\mathrm{cov}}=1.4(0.3)+0.6(0.4)=0.42+0.24=0.66. $$

The weights average to one under the source covariate distribution: \(0.5(1.4)+0.5(0.6)=1\). This is a target risk estimate only if the conditional error given \(X\) transfers from source to target.

Why Covariate Weighting Works Under Its Assumption

The population identity behind the calculation is a change of measure. Write \(r(x)=p_T(x)/p_S(x)\) when densities exist, or use the corresponding Radon–Nikodym derivative for general distributions. The support condition means \(P_T\) is absolutely continuous with respect to \(P_S\) on \(X\), so this ratio is defined \(P_T\)-almost surely.

Result: If \(P_T(Y\mid X)=P_S(Y\mid X)\) and \(P_T\ll P_S\) on \(X\), then for any integrable loss, \(R_T=E_S[r(X)\ell(g(X),Y)]\).

To verify the identity, let \(m_S(x)=E_S[\ell(g(X),Y)\mid X=x]\) and define \(m_T\) analogously. Equality of the conditional distributions implies \(m_T(x)=m_S(x)\) for \(P_T\)-almost every \(x\). Therefore

$$ R_T =\int m_T(x)\,dP_T(x) =\int m_S(x)r(x)\,dP_S(x) =E_S[r(X)\ell(g(X),Y)]. $$

The last equality follows by conditioning the source expectation on \(X\). In the finite binary example, the integral is just the sum over \(a\) and \(b\), producing the two weighted error contributions above. Large or unstable ratios can make the sample estimate variable even when the identity is correct.

Label-Shift Correction from Unlabeled Covariates

Under label shift, the class-conditional distribution of \(X\) transfers instead. From the source table, \(P_S(X=a\mid Y=1)=300/400=0.75\), while \(P_S(X=a\mid Y=0)=200/600=1/3\). Let \(\pi_T=P_T(Y=1)\). If label shift holds, the target marginal probability of \(a\) satisfies \(P_T(X=a)=0.75\pi_T+(1/3)(1-\pi_T)\). Thus an unlabeled target covariate proportion can identify the target class prevalence here because the two source class-conditional probabilities differ.

Worked Example: Inferring Target Prevalence and Risk

Set the target proportion \(P_T(X=a)\) to its observed value, 0.7, and solve:

$$ 0.7=0.75\pi_T+\frac{1}{3}(1-\pi_T) =\frac{1}{3}+\frac{5}{12}\pi_T, \qquad \hat\pi_T=\frac{0.7-1/3}{5/12}=0.88. $$

The source error rate conditional on \(Y=1\) is \(300/400=0.75\); for \(Y=0\) it is \(400/600=2/3\). Under label shift, the target risk is the prevalence-weighted sum of these class-conditional errors:

$$ \hat R_{\mathrm{label}} =0.88(0.75)+0.12\left(\frac{2}{3}\right) =0.66+0.08 =0.74. $$

This differs from the covariate-weighted estimate of 0.66 despite using the same target covariate proportion. Label shift changes the target mixture of classes; covariate shift keeps the conditional label distribution given \(X\) fixed. The data do not justify switching between these answers without assessing which transfer assumption is credible.

The label-shift risk calculation also has a direct derivation. Under label shift, condition first on \(Y\): the conditional expected loss given each class is the same in source and target. If \(r_y=E_S[\ell\mid Y=y]\) and \(\pi_T=P_T(Y=1)\), then

$$ R_T =\sum_{y\in\{0,1\}}P_T(Y=y)E_T[\ell\mid Y=y] =\pi_T r_1+(1-\pi_T)r_0. $$

For prevalence identification, put \(q_a=P_T(X=a)\), \(u_1=P_S(X=a\mid Y=1)\), and \(u_0=P_S(X=a\mid Y=0)\). The label-shift equation is \(q_a=u_0+(u_1-u_0)\pi_T\). If \(u_1\ne u_0\), its unique solution is \(\pi_T=(q_a-u_0)/(u_1-u_0)\). A solution outside \([0,1]\) signals incompatibility between the observed marginal and this fitted label-shift model, rather than a valid prevalence estimate. Here \(u_1=0.75\ne 1/3=u_0\), and the solution 0.88 is in range.

A Robust Estimate Across Competing Models

A robust estimate can protect against uncertainty about which transfer model is appropriate, but it is only meaningful after specifying the candidate models and the uncertainty set. For this example, use an approximate 95% Wald interval for the target proportion \(q_a\). From 70 occurrences of \(a\) in 100 independent target observations, \(\hat q_a=0.70\) and its estimated standard error is \(\sqrt{0.7(0.3)/100}=0.0458\). The interval is \(0.70\pm1.96(0.0458)\), approximately \([0.610,0.790]\). This interval accounts for target covariate sampling only, not for source estimation or model misspecification.

Worked Example: Worst-Case Risk Over Two Shift Models

Define a sensitivity set consisting of either covariate shift with \(q_a\in[0.610,0.790]\), or label shift with \(q_a\) in that interval and compatible with a prevalence between zero and one. Under covariate shift, the transferred risk at a given \(q_a\) is

$$ R_{\mathrm{cov}}(q_a)=0.6q_a+0.8(1-q_a)=0.8-0.2q_a. $$

This decreases as \(q_a\) increases, so its maximum over the interval is at 0.610: \(0.8-0.2(0.610)=0.678\).

Under label shift, compatibility requires \(q_a=1/3+(5/12)\pi_T\) with \(0\leq\pi_T\leq1\), hence \(1/3\leq q_a\leq0.75\). Intersecting this range with the sampling interval gives \([0.610,0.750]\). The label-shift risk is

$$ R_{\mathrm{label}}(\pi_T) =0.75\pi_T+\frac{2}{3}(1-\pi_T) =\frac{2}{3}+\frac{\pi_T}{12}. $$

It increases with \(\pi_T\), so its maximum occurs at \(\pi_T=1\), equivalently \(q_a=0.75\), and equals \(0.75\). The worst case over the union of the two models is therefore \(\max(0.678,0.750)=0.750\).

This robust value is not a third fitted description of the observed target population. It is an upper bound over the specified set of possibilities. Its value depends on the interval, on which shift mechanisms are included, and on the transferred source rates being treated as fixed. A broader or differently constructed uncertainty set can yield a different worst case.

Uncertainty, Assumptions, and a Common Pitfall

There are at least three uncertainty sources to keep separate. First, the target proportion \(q_a\) is estimated from a finite unlabeled sample; the interval above addresses this component approximately. Second, source conditional error rates and class-conditional covariate probabilities are estimated from finite labeled data. Third, the choice of shift assumption is structural: sampling more target covariates does not by itself determine whether covariate shift or label shift holds. The robust calculation addresses the third issue only to the extent that its model set contains the plausible mechanisms.

A frequent mistake is to say, “Target covariates are observed, so reweighting gives the target risk.” Reweighting gives the target risk only if the conditional label distribution given \(X\) transfers and the required support condition holds. In this example, reweighting gives 0.66 under covariate shift, while label shift gives 0.74 from the same observed marginal. Unlabeled covariates alone do not reveal which conditional relationship is true. A second pitfall is to interpret the robust maximum as an estimate with a guaranteed coverage level: the Wald interval is approximate, source uncertainty was held fixed, and the model set may omit the true target distribution.

In practice, report the assumption beside each transferred risk, check whether the fitted prevalence is feasible, and examine sensitivity to sampling and model uncertainty. Weighting can be unstable when target-to-source ratios are large; label-shift correction can be unstable when the class-conditional covariate distributions are nearly indistinguishable. Robustness is useful when its uncertainty set is explicit, but it cannot repair an implausible or incomplete set of assumptions.

Check Your Understanding

Use the counts and assumptions in this example to answer the following questions.

  1. What covariate density ratio is assigned to \(X=b\), and why do the two empirical ratios average to one under the source covariate proportions?
  2. If the target proportion of \(a\) were 0.60, what target prevalence would the fitted label-shift equation imply? Is that value feasible?
  3. Why can covariate weighting and label-shift correction produce different risks even though they use the same unlabeled target sample?
  4. Which endpoint of the target-proportion interval maximizes the covariate-shift risk, and which compatible endpoint maximizes the label-shift risk?
  5. Name one uncertainty source included in the robust example and two sources it leaves unaccounted for.
Clinical Biostats