The inputs of the training set (source) come from p(x) = N(0, 1); the test inputs (target) come from q(x) = N(m, s²); the regression function f is the same in both. A polynomial is fitted by least squares to the source points (pink) and, with weights w(x) = q(x)/p(x), by weighted least squares (teal). The dashed white curve is the best polynomial for the target (what weighting reaches with infinitely many points). If the model can represent f exactly, the shift is harmless; if it cannot, the source fit is wrong where the target lives. Weighting cures the bias but raises the variance: the effective sample size says by how much.
The "population" rows are exact (numerical integration on a fine grid); the "this run" rows use one random sample of N source points (and N unlabelled target points for the classifier weights) and the target error is integrated exactly over q; the "200 runs" row repeats the whole experiment. Errors are mean squared errors about f and exclude the noise variance 0.0625.
code/ch19_beyond_iid.py (covariate_shift_experiment, density_ratio_logistic, cs_population).