Under covariate shift, how do you derive the importance-weighted loss Etest[ℓ]=Etrain[w(x) ℓ] and estimate w(x) using a domain classifier? Given ntrain=800 training points and ntest=200 unlabelled test points, four training examples receive calibrated domain probabilities P(test∣x)=[0.2,0.2,0.5,0.8] and per-example losses [0.1,0.2,0.3,0.8]: what are their importance weights, the weighted loss, and the ESS (effective sample size), and why does this fail under concept drift?

ML systems and evaluation, Distribution shift
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can derive importance-weighted risk estimation and training under covariate shift, estimate density ratios with a domain classifier, diagnose variance via ESS (effective sample size), and recognise when the assumption breaks.

Key idea

Covariate shift assumes the input density changes from ptrain(x) to ptest(x) while the conditional label distribution p(y∣x) stays fixed. Multiplying and dividing the test expectation by ptrain(x) yields Etest[ℓ]=Etrain[w(x) ℓ] with w(x)=ptest(x)/ptrain(x), letting you evaluate or retrain a model on labelled training data as if it were drawn from the test distribution.

Steps

  1. Derive the identity: let ℓ=ℓ(f(x),y) be the loss of predictor f on input x and label y. Assuming ptrain(x)>0 wherever ptest(x)>0 and ptest(y∣x)=ptrain(y∣x)=p(y∣x), rewrite the test expected loss as Eptest[ℓ]=∬ℓ ptest(x) p(y∣x) dx dy=∬ptest(x)ptrain(x) ℓ ptrain(x) p(y∣x) dx dy=Eptrain[w(x) ℓ], with importance weight w(x)=ptest(x)/ptrain(x).
  2. Estimate w(x) with a domain classifier: pool the ntrain training inputs (label s=0) and ntest unlabelled test inputs (label s=1), giving prior ratio P(s=0)/P(s=1)=ntrain/ntest. By Bayes' rule on ptest(x)=p(x∣s=1) and ptrain(x)=p(x∣s=0), w(x)=p(x∣s=1)p(x∣s=0)=P(s=1∣x)P(s=0∣x)⋅P(s=0)P(s=1)=P(test∣x)P(train∣x)⋅ntrainntest.
  3. Compute the weights on the example: here ntrain/ntest=800/200=4 and P(train∣x)=1−P(test∣x). Thus w1=0.20.8⋅4=1, w2=0.20.8⋅4=1, w3=0.50.5⋅4=4, and w4=0.80.2⋅4=16.
  4. Compute the weighted loss and ESS: the unweighted mean loss is (0.1+0.2+0.3+0.8)/4=0.35. With ∑wi=22, the self-normalised weighted loss is (1⋅0.1+1⋅0.2+4⋅0.3+16⋅0.8)/22=14.3/22=0.65. Since ∑wi2=12+12+42+162=274, the effective sample size is ESS=(∑wi)2∑wi2=222274=484274≈1.77 out of 4.
  5. Control variance with weight clipping: one example with w4=16 carries 16/22≈73% of the total weight, inflating variance for both evaluation and reweighted training. Clipping weights at a cap M (for instance M=5 gives w=[1,1,4,5], raising ESS to 112/43≈2.81 and weighted loss to 0.50) trades a small bias for much steadier estimates.
  6. Explain why fixed p(y∣x) matters: the derivation relies on ptest(y∣x)=ptrain(y∣x). Under concept drift, where p(y∣x) itself changes between training and deployment, reweighting x cannot correct shifted labels, so you need fresh target labels to evaluate or retrain.

Common mistakes

How long your answer should be

3–4 minutes: short derivation, domain-classifier formula, weights and ESS arithmetic, and two sentences on clipping and concept drift.

Read this

Previous in ML systems and evaluation: In online A/B testing, CUPED reduces metric variance by replacing the outcome Y with Ycuped=Y−θ(X−E[X]), where X is a pre-experiment covariate unaffected by treatment. How do you show that E[Ycuped]=E[Y] (unbiasedness), derive the variance-minimising θ∗, and prove that the minimum variance is Var⁡(Y)(1−ρ2) where ρ=Corr⁡(X,Y)?
Next in ML systems and evaluation: How do you use the two-sample KS (Kolmogorov–Smirnov) test to detect drift in a model's prediction scores? Suppose 6 reference scores are [0.10,0.20,0.30,0.40,0.50,0.75] and 6 live scores are [0.55,0.65,0.70,0.80,0.85,0.95]: what are the empirical CDFs (cumulative distribution functions), the KS statistic D, and the comparison against the large-sample α=0.05 critical value, and why do production teams alert on effect size rather than p-values?