Dataset shift and robustness
Quick answer
Dataset shift occurs when the data encountered after deployment differs from the development data. Robustness is the ability to maintain acceptable behavior under specified changes, not a promise of accuracy on arbitrary inputs. Examples are static Python snippets tested locally on CPU; The confusion matrix example requires scikit-learn; exercises use standard-library Python. ByteMind execution is unverified.
Paired prediction sensitivity
x=[4,5,7]a=[v>=5 for v in x]; b=[v+1>=5 for v in x]print(sum(p!=q for p,q in zip(a,b)),len(x))Expected output (locally tested): 1 3. One paired decision changes.
How it works
Write P_train(X,Y) and P_live(X,Y) for the joint distributions of features and outcomes. Covariate shift changes P(X) while keeping P(Y|X) fixed; label shift changes P(Y) while keeping P(X|Y) fixed; concept drift changes P(Y|X). These are idealized cases and may overlap in practice. Unlabeled feature drift is observable but cannot establish concept drift without outcome evidence. For a sensor classifier, simulate benign rounding or a known measurement offset before deployment. Compare the original and perturbed predictions on the same rows: flip rate is the fraction of changed predictions, whereas accuracy change requires ground truth. A stable wrong prediction is still wrong. Preserve the latent outcome when the perturbation represents measurement noise, not a real change in equipment condition. Define plausible units and ranges, perturb one factor at a time when diagnosing causes, and report both average and subgroup sensitivity. Fit scaling and thresholds on development data only. A frozen pipeline and paired holdout comparisons prevent choosing a favorable perturbation after seeing results. Monitor missingness, operating modes and delayed labels; trigger investigation rather than automatic retraining from unverified data.
Stable but incorrect
y=[1,0,1]; a=[0,0,0]; b=a.copy()print(sum(p!=q for p,q in zip(a,b)),sum(p==q for p,q in zip(a,y)))Expected output (locally tested): 0 1. No flips does not imply correctness.
Common mistakes
Do not treat a feature histogram change as proof of concept drift or a low flip rate as proof of correctness. Do not tune perturbations on final holdout outcomes.
Practice and next steps
For a threshold of 5, classify readings [4,5,7] before and after a +1 sensor offset. Calculate the flip rate and discuss whether true equipment conditions changed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dataset shift and robustness — knowledge check
Apply dataset shift and robustness to small examples and debugging scenarios.
Which change defines covariate shift in the idealized case?
What does a flip rate measure?
Can unlabeled feature drift prove concept drift?
Which perturbation is a benign measurement test?
When should perturbation magnitude be chosen?