Every statistical guarantee in §3.5 assumed that deployment data come from the exact same distribution p_S(\mathbf{x}, y) as our training and test splits. In practice, deployment distributions p_T(\mathbf{x}, y) drift constantly:
Passive & active shifts: Cameras and hospital scanners are upgraded (photos \to cartoons), seasonal epidemics alter disease prevalence overnight, and deployed decision rules trigger strategic human adaptation (Goodhart’s law: approving loans for Oxford shoes causes applicants to switch shoes without lowering default risk).
Unidentifiability from unlabeled inputs: Because p_T(\mathbf{x}) = p_S(\mathbf{x}), no test on unlabeled target inputs can ever detect the swap (100\% source accuracy \to 0\% target accuracy).
Two Factorizations Define Three Shift Regimes
Taxonomy of Distribution Shift
Every joint distribution p(\mathbf{x}, y) factors in two causal directions:
Concept shift: The conditional rule p(y \mid \mathbf{x}) itself drifts across geography or time (“soda” vs. “pop”).
Comparing the Three Shift Regimes Geometrically
1D Input Densities and Optimal Bayes Boundaries
Source (top) vs. target (bottom) joint densities p(x, y); the dotted line is the Bayes-optimal boundary:
Covariate shift (left):p(x) shifts right while p(y \mid x) and the Bayes boundary stay fixed—yet a misspecified model fitted where p_S(x) is dense can fail where p_T(x) lives.
Label shift (middle) & concept shift (right): Changing p(y) moves the boundary toward the rarer class via p(y \mid x) \propto p(x \mid y)p(y); concept shift alters p(y \mid x) directly.
Covariate vs. Label Shift in Detail
Why Misspecified Models Need Reweighting
Covariate shift (p(y \mid \mathbf{x}) fixed): If \mathcal{F} contained the true p(y \mid \mathbf{x}), fitting on infinite source data would be optimal everywhere. A limited model (a line for a curved boundary) instead sacrifices accuracy where p_S(\mathbf{x}) is small.
Label shift (p(\mathbf{x} \mid y) fixed): Adaptation needs only q class proportionsp_T(y), not a density ratio over \mathbb{R}^d.
Concept Shift: When the Labeling Rule Moves
Geographic and Temporal Drift
Shifting label semantics: In concept shift, the conditional distribution p(y \mid \mathbf{x}) itself changes—identical product features or beverage descriptions map to "pop" in the Midwest, "soda" in the Northeast, and "coke" in the South.
Why unlabeled inputs cannot fix concept shift: When p(y \mid \mathbf{x}) drifts without changing p(\mathbf{x}), historical labels are outdated; adaptation requires collecting a trickle of fresh target labels and fine-tuning or retraining continuously.
Importance Weighting Under Covariate Shift
Aligning Source Training with Target Risk
Under covariate shift (p_T(y \mid \mathbf{x}) = p_S(y \mid \mathbf{x}) = p(y \mid \mathbf{x})) with support overlap (p_S(\mathbf{x}) > 0 wherever p_T(\mathbf{x}) > 0), target risk rewrites as a weighted expectation over p_S (Shimodaira, 2000):
Weighted ERM: On n labeled source examples, minimize \frac{1}{n}\sum_{i=1}^n \beta_i\,l(f(\mathbf{x}^{(i)}), y^{(i)}).
Support Overlap, Right-Tail Explosion & Weight Clipping
Variance and Effective Sample Size
Importance weighting faces two fundamental statistical hazards:
Missing support (p_S(\mathbf{x}) = 0 where p_T(\mathbf{x}) > 0): If source controls include only 20-year-olds while target patients are 70-year-olds, \beta(\mathbf{x}) is undefined and no reweighting of 20-year-olds can manufacture 70-year-old data.
Weight explosion & effective sample size (n_{\text{eff}}): For p_S = \mathcal{N}(0,1) and p_T = \mathcal{N}(2,1), \beta(x_1) = e^{2x_1 - 2} reaches 55 at x_1 = 3, collapsing: n_{\mathrm{eff}} = \frac{\big(\sum_{i=1}^n \beta_i\big)^2}{\sum_{i=1}^n \beta_i^2} \ll n
Weight clipping: Capping \tilde{\beta}_i = \min(\beta_i, c) (e.g., c = 5) trades a small bias for a large reduction in variance.
Estimating Density Ratios via a Domain Classifier
Avoiding High-Dimensional Density Estimation
Instead of estimating p_S(\mathbf{x}) and p_T(\mathbf{x}) separately in \mathbb{R}^d, pool n source inputs (z = 0) with m unlabeled target inputs (z = 1) and train a logistic domain classifierP(z = 1 \mid \mathbf{x}) = \sigma(h(\mathbf{x})):
Direct density-ratio formula:\beta(\mathbf{x}) = \frac{n}{m}\exp(h(\mathbf{x})) \propto \exp(h(\mathbf{x})), requiring zero target labels.
2D Covariate Shift Benchmark: Setup
Parabolic True Boundary Under a Shifted Gaussian
Let p_S = \mathcal{N}(\mathbf{0}, \mathbf{I}_2), p_T = \mathcal{N}((2, 0)^\top, \mathbf{I}_2), and true invariant rule y = \mathbf{1}(x_2 > \frac{1}{2}x_1^2 - 1):
rng = np.random.default_rng()n =1000X_src = rng.normal(0, 1, (n, 2)) # source p_S: centered at (0, 0)X_tgt = rng.normal(0, 1, (n, 2)) + [2, 0] # target p_T: centered at (2, 0)label =lambda X: (X[:, 1] >0.5* X[:, 0]**2-1).astype(float)y_src, y_tgt = label(X_src), label(X_tgt) # one labeling rule for both
Training the Domain Classifier & Importance Weights
Parabolic True Boundary Under a Shifted Gaussian
Pooling X_src(z = 0) and X_tgt(z = 1) estimates the log density ratio h(\mathbf{x}), the source weights \beta_i = \exp(h(\mathbf{x}^{(i)})), and their effective sample size:
Unweighted vs. Importance-Weighted vs. Clipped ERM
Weighting each source example’s gradient residual by \beta_i = \exp(h(\mathbf{x}^{(i)})) inside fit_logreg:
def fit_logreg(X, y, weights=None, lr=0.1, steps=2000):"""Logistic regression by gradient descent on the weighted mean loss.""" w, b = np.zeros(X.shape[1]), 0.0 v = np.ones(len(y)) if weights isNoneelse weights / weights.mean()for _ inrange(steps): r = v * (1/ (1+ np.exp(-(X @ w + b))) - y) # weighted error w -= lr * X.T @ r /len(y) b -= lr * r.mean()return w, b
Unweighted vs. Importance-Weighted vs. Clipped ERM
Reweighting lifts target accuracy from \sim 50\%–60\% to \sim 95\% without a single target label:
acc =lambda wb, X, y: ((X @ wb[0] + wb[1] >0) == (y ==1)).mean()models = {name: fit_logreg(X_src, y_src, v) for name, v in [ ('unweighted', None), ('weighted', beta), ('clipped', np.minimum(beta, 5))]}for name, wb in models.items():print(f'{name:10s} target accuracy {acc(wb, X_tgt, y_tgt):.3f}'f' source accuracy {acc(wb, X_src, y_src):.3f}')print(f'always predicting the most common target class: 'f'{max(y_tgt.mean(), 1- y_tgt.mean()):.3f}')
unweighted target accuracy 0.603 source accuracy 0.853
weighted target accuracy 0.945 source accuracy 0.854
clipped target accuracy 0.944 source accuracy 0.854
always predicting the most common target class: 0.711
How Importance Weights Tilt the Linear Decision Boundary
Geometric Effect of Covariate Shift Correction
Plotting the source cloud (circle area \propto \beta_i), the shifted target cloud (orange), and the fitted linear boundaries explains the accuracy jump of 35 to 45 points:
Unweighted linear boundary (green): Fits the bottom of the parabola near (0, 0) with a nearly horizontal line (x_2 \approx -0.6), misclassifying almost half the target cloud around (2, 0).
Importance-weighted boundary (red): Downweights points near x_1 \le 0 and emphasizes source points in the right tail (x_1 > 1), tilting the line to hug the right arm of the parabola where the target data live.
Label Shift Correction via the Confusion Matrix
Black-Box Shift Estimation (BBSE / Saerens et al.)
Under label shift(p_T(\mathbf{x} \mid y) = p_S(\mathbf{x} \mid y),p_T(y) \neq p_S(y)), how do we estimate unknown target priors \mathbf{p}_T \in \mathbb{R}^q from unlabeled target inputs?
Invariance of column-normalized confusion matrix \mathbf{C}: Because p(\mathbf{x} \mid y) is invariant, C_{ij} = P(\hat{c}(\mathbf{x}) = i \mid y = j) is identical on source and target.
Law of total probability on target predictions \boldsymbol{\mu}:\mu_i = P_T(\hat{c}(\mathbf{x}) = i) = \sum_{j=1}^q C_{ij}\,p_T(y = j) \iff \mathbf{C}\,\mathbf{p}_T = \boldsymbol{\mu}
Inverting C to Recover Target Class Proportions
Worked Clinical Example & Invertibility Condition
Whenever \mathbf{C} is invertible (guaranteed if per-class recall C_{jj} > 1/2), solving \hat{\mathbf{p}}_T = \mathbf{C}^{-1}\boldsymbol{\mu} recovers target class priors with zero target labels:
Worked clinical example (90\% sensitivity, 5\% FPR): When a winter clinic sees \mu_2 = 13.5\% positive flags: 0.05(1 - p) + 0.90p = 0.135 \implies 0.85p = 0.085 \implies p = 0.10 unscrambling 10\% true flu prevalence from the 4.5\% false alarms and 1\% missed cases.
Unscrambling Label Shift on Fashion-MNIST
50% Shirt Surge & Instant Bayes Logit Adjustment
Estimating \mathbf{C} on 5{,}000 balanced validation images and testing on an unlabeled target set where shirts surge from 10\% to 50\%:
log_w = np.log(np.maximum(p_hat, 1e-6) /0.1) # log p_T(y) - log p_S(y)accuracy =lambda O: (O.argmax(axis=1) == y[tgt]).mean()print(f'target accuracy: {accuracy(O[tgt]):.3f} as trained, 'f'{accuracy(O[tgt] + log_w):.3f} adapted to the estimated proportions')
target accuracy: 0.706 as trained, 0.816 adapted to the estimated proportions
Instant Bayes Logit Adjustment
50% Shirt Surge & Instant Bayes Logit Adjustment
Instant Bayes logit adjustment: Adding \log\frac{\hat{p}_T(y)}{p_S(y)} to each class logit lifts target accuracy by \sim 5\text{--}15 points in zero gradient steps.
No retraining: The source weights stay fixed; only the class priors move.
Concept Shift and Performative Feedback Loops
When the Model Reshapes Its Own Environment
In deployed socio-technical systems, predictions do not merely observe the world—they trigger actions that alter future data distributions (performative prediction):
Runaway feedback loop in predictive policing: High predicted crime in neighborhood A dispatches extra patrols to A; increased patrol presence records more minor offenses in A while leaving neighborhood B unpatrolled; retraining on logged arrests reinforces the initial bias.
Breaking feedback loops: Passive importance reweighting cannot fix data censored by the model’s own decisions; auditing requires randomized exploration (bandits / RL) or independent outcome measurement.
Concept Check: Diagnosing & Fixing Distribution Shift
Concept Check
Test your diagnostic and mathematical understanding of distribution shift:
Classifying shifts: Identify whether each scenario is covariate shift, label shift, or concept shift: (a) upgrading a highway toll camera to higher contrast; (b) a summer heatwave tripling the share of sandal orders in an online store; (c) a psychiatry manual revising the diagnostic criteria for a condition.
Importance weight ratio: In our 2D Gaussian example where \beta(\mathbf{x}) = \exp(2x_1 - 2), how many times more weight does a source point at (3, 0) carry compared to a source point at (1, 0), and what is the theoretical large-n effective sample size n_{\text{eff}} / n = 1 / \mathbb{E}_S[\beta^2] for shift distance s = 2(\mathbb{E}_S[\beta^2] = e^{s^2})?
Unidentifiability without causal knowledge (Exercise 5): If unlabeled target inputs x shift toward positive values, can any statistical test on the unlabeled target inputs tell you whether covariate shift or label shift occurred?
Answers:(1)(a) Covariate shift (p(\mathbf{x}) changes, vehicle identity p(y\mid\mathbf{x}) stays fixed); (b) Label shift (p(y) changes, product photo p(\mathbf{x}\mid y) stays fixed); (c) Concept shift (p(y\mid\mathbf{x}) changes). (2)\beta(3,0) = e^4 \approx 54.6 vs. \beta(1,0) = e^0 = 1(54.6\times more weight); theoretically n_{\mathrm{eff}} \approx n e^{-s^2} = 1000 e^{-4} \approx 18.3 effective examples. (3) No: the exact same target marginal p_T(x) can arise either from p_T(x) shifting with p(y\mid x) fixed (where the optimal threshold stays fixed) or from p_T(y=1) rising with p(x\mid y) fixed (where the optimal threshold moves). Choosing the right correction requires causal domain knowledge.
Summary: Distribution Shift Regimes and Corrections
Section Summary
Shift Regime
Invariant Factor
Correction Algorithm
Key Requirement & Pitfall
Covariate shift
p(y \mid \mathbf{x}) fixed (p(\mathbf{x}) shifts)
Weighted ERM with \beta(\mathbf{x}) = \frac{p_T(\mathbf{x})}{p_S(\mathbf{x})} \propto \exp(h(\mathbf{x})) from logistic domain classifier
Requires support overlap (p_S > 0 where p_T > 0); clip \min(\beta_i, c) to preserve n_{\mathrm{eff}}
Label shift
p(\mathbf{x} \mid y) fixed (p(y) shifts)
Solve \mathbf{C}\,\hat{\mathbf{p}}_T = \boldsymbol{\mu} for target priors; reweight by \hat{p}_T(y)/p_S(y) or shift logits by +\log\frac{\hat{p}_T(y)}{p_S(y)}