Tutorials › Multivariate Statistics (Graduate) › Importance-Weighted Risk Under Covariate Shift

Discriminant Inference and Risk · Tutorial 625 of 975

Importance-Weighted Risk Under Covariate Shift

Learn when and how source observations can be reweighted to estimate a classifier’s risk in a target population with a different feature distribution.

Advanced 11 min read

What You'll Learn

  • Define covariate shift through invariant class-conditional distributions and changing feature marginals
  • Derive the target-risk change-of-measure identity using a feature-density ratio
  • Construct and interpret an importance-weighted empirical risk estimate
  • State the conditions for unbiasedness, consistency, and finite variance
  • Recognize the consequences of unsupported target regions and same-sample classifier fitting

Why Reweight Classification Risk?

A classifier may be evaluated in a population whose feature distribution differs from the population that supplied its labeled training or assessment data. For example, a diagnostic rule may be assessed in a clinic with a different mix of patient measurements. If the relationship between features and labels remains stable, the changed feature mix still changes the average error rate. Importance weighting expresses that target-population risk using labeled source observations.

The key distinction is between a change in the distribution of features and a change in the conditional distribution of labels given features. This tutorial considers the former: the class posterior is invariant, while the marginal distribution of the feature vector can differ. The resulting risk identity applies to a fixed classifier, including a fitted classifier when its evaluation observations are independent of the data used to fit it.

Definition: Let \(X\) be a feature vector and \(Y\) a class label. Write \(P_S\) and \(P_T\) for the source and target joint distributions. Covariate shift means that the feature marginals may differ, \(P_S^X \ne P_T^X\), but the conditional label distributions agree: \(P_S(Y\mid X=x)=P_T(Y\mid X=x)\) for \(P_T^X\)-almost every \(x\). For the weighting identity below, also require overlap: \(P_T^X\) is absolutely continuous with respect to \(P_S^X\), written \(P_T^X\ll P_S^X\). The feature-density ratio is \(r(x)=dP_T^X/dP_S^X(x)\).

Absolute continuity says that any feature region assigned zero probability by the source must also have zero probability in the target. When both feature distributions have densities \(f_S\) and \(f_T\) with respect to the same measure, the ratio is \(r(x)=f_T(x)/f_S(x)\) wherever \(f_S(x)>0\). The ratio changes the contribution of each source feature value according to how common it is in the target relative to the source.

The Target-Risk Identity

Let \(g\) be a measurable classifier mapping features to labels, and let \(L(g(X),Y)\) be a measurable loss. For misclassification risk, \(L(g(X),Y)=\mathbf{1}\{g(X)\ne Y\}\). More generally, the argument works for any nonnegative loss whose target expectation is finite.

Theorem: Under covariate shift and \(P_T^X\ll P_S^X\), the target risk of a fixed classifier is \(R_T(g)=E_T[L(g(X),Y)]=E_S[r(X)L(g(X),Y)]\), provided the loss is measurable and \(E_T[L(g(X),Y)]<\infty\).

To prove the identity, define \(h(x)=E_S[L(g(x),Y)\mid X=x]\). Conditional invariance implies that the same conditional expectation is obtained under \(P_T\), for \(P_T^X\)-almost every \(x\). The law of iterated expectation gives

$$ \begin{aligned} R_T(g) &= \int E_T[L(g(x),Y)\mid X=x]\,dP_T^X(x)\\ &= \int h(x)\,dP_T^X(x)\\ &= \int h(x)r(x)\,dP_S^X(x)\\ &= E_S[r(X)L(g(X),Y)]. \end{aligned} $$

The third equality is the defining change-of-measure property of the Radon–Nikodym derivative \(r\); the last follows by conditioning on \(X\) under the source distribution. Finiteness of the target risk ensures the integrals are well-defined. Thus source labels can identify target risk through a weighted expectation, without requiring target labels. \(\square\)

Worked Example: A Three-Region Feature Space

Suppose \(X\) takes values \(a,b,c\). The source probabilities are \(0.50,0.30,0.20\), and the target probabilities are \(0.20,0.30,0.50\), respectively. Assume conditional invariance. A fixed classifier has conditional error probabilities \(0.10,0.20,0.40\) at \(a,b,c\).

The feature ratios are \(r(a)=0.20/0.50=0.4\), \(r(b)=0.30/0.30=1\), and \(r(c)=0.50/0.20=2.5\). Directly in the target population, the risk is

$$ R_T(g)=0.20(0.10)+0.30(0.20)+0.50(0.40) =0.02+0.06+0.20=0.28. $$

The weighted source expectation gives the same result:

$$ E_S[r(X)L] =0.50(0.4)(0.10)+0.30(1)(0.20)+0.20(2.5)(0.40) =0.02+0.06+0.20=0.28. $$

By contrast, the unweighted source risk is \(0.50(0.10)+0.30(0.20)+0.20(0.40)=0.19\). It is lower because the source contains fewer observations from region \(c\), where this classifier has the highest error.

Estimating Risk from Labeled Source Observations

Suppose \((X_i,Y_i)\), \(i=1,\ldots,n\), are independent and identically distributed source observations. If \(g\) and the ratio \(r\) are fixed and the ratios are known, the empirical importance-weighted estimator is

$$ \widehat R_{T,\mathrm{IW}}(g) =\frac{1}{n}\sum_{i=1}^n r(X_i)L(g(X_i),Y_i). $$

For zero-one loss, each observed error is multiplied by the relative target frequency of that observation’s feature value. The estimator uses the source labels and feature ratios; it does not require a labeled target sample.

Theorem: If the source observations are independent and identically distributed, \(g\) is fixed independently of these observations, and \(E_S[r(X)L(g(X),Y)]<\infty\), then \(\widehat R_{T,\mathrm{IW}}(g)\) is unbiased for \(R_T(g)\). If the summands are integrable, then \(\widehat R_{T,\mathrm{IW}}(g)\xrightarrow{a.s.}R_T(g)\).

For unbiasedness, linearity of expectation and the risk identity give

$$ E_S[\widehat R_{T,\mathrm{IW}}(g)] =\frac{1}{n}\sum_{i=1}^n E_S[r(X_i)L(g(X_i),Y_i)] =R_T(g). $$

For consistency, the summands \(Z_i=r(X_i)L(g(X_i),Y_i)\) are independent and identically distributed, with \(E_S[|Z_i|]=R_T(g)<\infty\) for a nonnegative loss. The strong law of large numbers therefore gives \(n^{-1}\sum_i Z_i\xrightarrow{a.s.}E_S[Z_i]=R_T(g)\). \(\square\)

Worked Example: Calculating an Empirical Weighted Error

A held-out source sample contains five labeled observations. Their feature ratios are \(0.5,0.5,2,2,2\), and their classifier error indicators are \(0,1,0,1,1\). The ordinary sample error is \(3/5=0.60\).

The weighted loss contributions are \(0.5(0)=0\), \(0.5(1)=0.5\), \(2(0)=0\), \(2(1)=2\), and \(2(1)=2\). Therefore,

$$ \widehat R_{T,\mathrm{IW}}(g) =\frac{0+0.5+0+2+2}{5} =\frac{4.5}{5}=0.90. $$

This sample suggests greater target risk than the unweighted error because the observed errors receive large weights. It does not establish that the true target risk is \(0.90\): the estimate varies from sample to sample. Unbiasedness is a statement about its expectation across repeated source samples, not a guarantee that any particular estimate is close to the target risk.

When the summands have finite variance, independence also gives

$$ \operatorname{Var}_S\!\left(\widehat R_{T,\mathrm{IW}}(g)\right) =\frac{1}{n}\operatorname{Var}_S\!\left(r(X)L(g(X),Y)\right). $$

Thus large or highly variable ratios can make a risk estimate imprecise even when it remains unbiased. In particular, a finite target risk does not by itself guarantee finite estimator variance: that additionally requires \(E_S[(r(X)L(g(X),Y))^2]<\infty\). The existence of the weighting identity and the practical stability of its estimate are separate issues.

Worked Example: Why Support Matters

Let \(X\in\{0,1,2\}\). Suppose the source assigns probabilities \(P_S(X=0)=0.6\), \(P_S(X=1)=0.4\), and \(P_S(X=2)=0\). The target assigns probabilities \(0.3,0.4,0.3\). A classifier always predicts class 0, and labels are binary.

The source never observes \(X=2\), although the target assigns that feature value probability \(0.3\). Consider two possible conditional label models. In both, \(P(Y=1\mid X=0)=0\) and \(P(Y=1\mid X=1)=0\). In model A, \(P(Y=1\mid X=2)=0\); in model B, \(P(Y=1\mid X=2)=1\). Both models yield exactly the same source distribution of labeled observations, but both satisfy conditional invariance between source and target wherever the source has support.

Under model A, the classifier never errs, so its target risk is \(0\). Under model B, it errs whenever \(X=2\), so its target risk is \(0.3(1)=0.3\). No source-based weighting can distinguish these risks: the target mass at \(X=2\) is not covered by the source, and \(P_T^X\not\ll P_S^X\). The target risk is therefore not identified from the source labels and feature distribution under these assumptions alone.

Conditions and Common Pitfalls

Importance weighting is not an automatic correction for every difference between populations. It specifically relies on the assumption that the conditional label distribution is invariant. If \(P_T(Y\mid X)\) changes, reweighting source features cannot repair the changed relationship between features and labels. This is different from changing only the feature marginal, which is the setting considered here.

  • Using an unweighted source error. This estimates source risk, not target risk, unless the feature distributions agree or the particular losses happen to average the same way.
  • Ignoring overlap. If a target region has zero source probability, no finite feature ratio exists there, and its conditional error cannot be recovered from source labels by this identity.
  • Treating unbiasedness as precision. Large ratios can make individual observations influential and increase variance. An unbiased estimate can still be unstable in a finite sample.
  • Evaluating a fitted classifier on its own training observations. The fixed-classifier unbiasedness argument does not generally apply when the same observations were used to select or fit \(g\). Use independent evaluation observations, or an evaluation design that separates fitting from assessment.
  • Assuming the invariance condition follows from reweighting. The ratio changes the distribution of \(X\); it does not test or enforce equality of \(P_S(Y\mid X)\) and \(P_T(Y\mid X)\).

If \(g\) is trained on a separate data set, it can be treated as fixed when conditioning on that training data. An independent source evaluation sample then supports the same identity and estimator for the fitted rule, conditional on the rule. By contrast, when \(g\) is trained using the evaluation observations, its prediction errors and those observations are dependent; a separate justification is needed.

Key takeaway: Under invariant class posteriors and target support contained in source support, target risk equals the source expectation of loss multiplied by the feature-density ratio. The identity is exact; the estimator’s reliability still depends on overlap, finite-sample variability, and valid separation of classifier fitting from risk assessment.

Check Your Understanding

Use the assumptions and equations above to answer each question.

  1. State the two distributional conditions that define the setting in which feature-ratio weighting identifies target risk.
  2. If the target-to-source feature ratio at \(x\) is \(3\), what does this say about the relative target and source feature density at \(x\)?
  3. Why can an importance-weighted estimator be unbiased yet highly variable?
  4. What fails if the target assigns positive probability to a feature region that has zero source probability?
  5. Why does the fixed-classifier unbiasedness argument require care when the classifier is evaluated on its own fitting observations?
Clinical Biostats