Robust and Causal Machine Learning
Distribution Shift and Out-of-Distribution Detection · 16 min
Supervised learning theory assumes training and deployment data are drawn from the same underlying distribution, but this assumption routinely fails in practice: covariate shift occurs when the distribution of inputs changes between training and deployment while the relationship between inputs and outputs stays fixed, and Hidetoshi Shimodaira formalized a correction for exactly this case. His approach reweights each training example's contribution to the log-likelihood by the ratio of the target distribution's density to the training distribution's density at that point, so that examples resembling the deployment distribution count more heavily during fitting than examples that do not; he showed that this importance-weighted maximum likelihood estimator asymptotically minimizes the expected loss under the target distribution, even when the underlying parametric model is not perfectly correct. The core requirement for this correction is being able to estimate the density ratio between the two distributions, which is itself a nontrivial estimation problem when the shift is severe or the input space is high-dimensional.
Covariate shift is a relatively benign case because the input-output relationship is assumed unchanged; other forms of shift are harder. Label shift changes the proportion of each class between training and deployment while the class-conditional feature distributions stay fixed, and concept drift changes the input-output relationship itself over time, which no amount of reweighting the training distribution can fix, since the function being learned is no longer the same function that generated the deployment data. A model silently degraded by any of these shifts often shows no obvious warning sign in its outputs alone — it will still produce confident predictions — which is why detecting that deployment inputs no longer resemble the training distribution has become a distinct research problem in its own right, separate from correcting for the shift once detected. Detecting shift and correcting for it are genuinely distinct problems, since a system might correctly flag that its inputs look unfamiliar long before anyone has worked out what, if anything, can be done to adjust the model's predictions in response.
Dan Hendrycks and Kevin Gimpel established an influential and simple baseline for exactly this detection problem: they observed that a neural network's maximum softmax probability tends to be higher for correctly classified in-distribution examples than for either misclassified in-distribution examples or genuinely out-of-distribution inputs the network was never trained to recognize, and thresholding this maximum softmax score alone provides a usable, if imperfect, detector across vision, language, and speech tasks. Their explicit framing of this as a baseline rather than a solved problem is worth taking seriously: distinguishing miscalibrated overconfidence on unfamiliar inputs from genuine confidence on familiar ones remains an active area of research, with subsequent work exploring density-based, distance-based, and ensemble-disagreement detectors that often outperform the softmax baseline but with no method yet treated as definitively solving the problem across all settings. This partial progress matters practically: a deployed system that cannot flag unfamiliar inputs at all will apply its training-distribution confidence uniformly, including to cases where that confidence has no justification whatsoever.
Causal Discovery from Observational Data · 16 min
Standard supervised learning estimates statistical association — how a prediction changes as an input changes within the observed data — but many of the questions practitioners actually care about are causal: what would happen if we intervened and changed an input, rather than merely observed it taking a different value. Peter Spirtes, Clark Glymour, and Richard Scheines's account of causal discovery frames the goal as recovering the causal structure that generated observational data, usually represented as a directed acyclic graph in which an edge from one variable to another represents a direct causal influence, distinct from the mere statistical dependence a purely predictive model would detect. This recovery relies on a small set of assumptions connecting graph structure to the observed probability distribution: the causal Markov condition, which says each variable is independent of its non-effects given its direct causes, and faithfulness, which says the only independencies present in the data are exactly those implied by the graph's structure, ruling out coincidental cancellations that would otherwise mimic a different causal structure.
Under these assumptions, algorithms such as the PC algorithm that Spirtes, Glymour, and Scheines describe can recover a great deal of causal structure from purely observational data, without any experimental manipulation, by systematically testing conditional independence relationships among variables and using the pattern of dependencies and independencies to orient edges in the underlying graph. Critically, this procedure typically cannot recover a single fully oriented causal graph; instead it recovers an equivalence class of graphs that are all consistent with the same set of observed conditional independencies, meaning some causal directions remain genuinely ambiguous from observational data alone and require either additional structural assumptions or actual experimental intervention to resolve. This is not a limitation of any particular implementation of the algorithm but a fundamental feature of what conditional-independence relationships alone can and cannot distinguish, since two causal structures that produce identical patterns of statistical dependence are, by definition, indistinguishable using only those patterns.
Jonas Peters, Dominik Janzing, and Bernhard Schölkopf's treatment of causal inference develops complementary approaches that can sometimes break this ambiguity using additional structural assumptions, such as restricting the functional form of how causes combine to produce effects, which can make certain causal directions identifiable even in the two-variable case where conditional-independence-based methods alone provide no information at all. It is worth being direct about the limits of this entire enterprise: causal discovery from purely observational data is a genuinely open and actively researched problem, not a solved one, because its guarantees depend on assumptions — faithfulness, no unmeasured confounders in some variants, correctly specified functional forms in others — that cannot themselves be verified from the same observational data being analyzed, and different assumption sets can lead to different, sometimes conflicting, conclusions about the same dataset. This is not a reason to dismiss causal discovery, since the alternative of ignoring causal structure entirely and treating every association as potentially actionable is worse, but it is a reason to treat any causal discovery output as a hypothesis meriting further scrutiny rather than a settled conclusion.
Estimating Treatment Effects from Observational Data · 15 min
Even when a causal question is narrower than full structure discovery — simply, does this treatment cause this outcome, and by how much — observational data introduces a specific obstacle: confounding, where some third variable influences both who receives the treatment and what outcome they experience, making a naive comparison of treated versus untreated outcomes reflect a mix of the true treatment effect and the confounder's influence. Paul Rosenbaum and Donald Rubin's foundational analysis addressed this by introducing the propensity score, defined as the conditional probability of receiving treatment given a unit's observed covariates, and proved a result that is easy to underestimate the significance of: adjusting for this single scalar summary is sufficient to remove the bias attributable to all of the measured covariates that went into computing it, even though those covariates might number in the dozens or hundreds. This is a genuinely surprising dimensionality reduction: instead of having to match treated and untreated units on every individual covariate simultaneously, which becomes practically impossible as the number of covariates grows, an analyst only has to match on the single number that summarizes each unit's estimated probability of treatment.
Rosenbaum and Rubin's paper laid out several concrete ways to use this result. Matching pairs treated and untreated units with similar propensity scores, so that within each matched pair, treatment assignment looks close to random with respect to the measured covariates. Subclassification groups units into strata of similar propensity score and compares treated and untreated outcomes within each stratum before combining the stratum-level estimates. A closely related approach not covered in their original paper but now standard, inverse propensity weighting, instead reweights every unit by the inverse of its probability of having received the treatment it actually received, which upweights treated units who looked unlikely to be treated and untreated units who looked likely to be treated — the units whose treatment status was most informative precisely because it went against what their covariates would predict. Each of these three approaches — matching, subclassification, and inverse propensity weighting — makes a different trade-off between how much of the available data is used and how sensitive the resulting estimate is to units with propensity scores near zero or one, where the weighting can become unstable.
All of these propensity-based methods share a critical limitation that no amount of clever weighting can overcome: they only adjust for confounders that were actually measured and included in computing the propensity score. If some unmeasured variable independently influences both treatment assignment and the outcome, the resulting effect estimate remains biased regardless of how sophisticated the adjustment technique is, a vulnerability usually described as sensitivity to unmeasured confounding. This is precisely why randomized experiments remain the gold standard for causal effect estimation whenever they are feasible and ethical to run — randomization guarantees, by construction, that treatment assignment is independent of every covariate, measured or not — and why observational causal-effect estimates are typically reported alongside sensitivity analyses that assess how strong an unmeasured confounder would need to be to overturn the conclusion. Such analyses do not prove that no unmeasured confounder exists, but they at least make explicit how fragile or robust a given causal conclusion is to the possibility of one, which is a meaningfully more honest position than presenting an observational estimate as though it settled the question outright.
A Confounded Treatment Effect
Z is a confounder affecting both who gets treated (T) and the outcome (Y), alongside T's own direct causal effect on Y (violet arrow). In the four-unit toy example, treated units average 11 and untreated units average 7, a naive difference of 4, but inverse-propensity weighting — which corrects for Z's influence on who was treated — brings the estimate down to about 3.5, illustrating how an unadjusted comparison can overstate a treatment's effect.
- Distribution shift comes in distinguishable forms — covariate shift, label shift, concept drift — and only some of them, like covariate shift, can be corrected by reweighting training data; concept drift changes the function being learned and reweighting cannot fix that.
- Out-of-distribution detection using softmax confidence is a genuinely useful, genuinely unsolved baseline: a model can be confidently wrong on unfamiliar inputs, and no detector yet reliably distinguishes miscalibrated overconfidence from legitimate confidence across all settings.
- Causal discovery from observational data and propensity-score adjustment both rest on assumptions — faithfulness, no unmeasured confounding — that cannot be verified from the same data being analyzed, which is why randomized experiments remain the gold standard whenever they are feasible.
Recall Practice
Glossary
- Covariate shift
- A form of distribution shift in which the distribution of inputs differs between training and deployment while the true input-output relationship remains unchanged.
- Concept drift
- A form of distribution shift in which the underlying relationship between inputs and outputs itself changes over time, which reweighting the training distribution cannot correct.
- Out-of-distribution (OOD) detection
- The task of identifying deployment-time inputs that differ substantially from the distribution a model was trained on, so that its predictions on them can be flagged as unreliable.
- Causal discovery
- The problem of inferring causal structure, typically represented as a directed acyclic graph, from observational or experimental data, distinct from merely detecting statistical association.
- Confounder
- A variable that influences both treatment assignment and the outcome, creating a spurious association between treatment and outcome if not properly adjusted for.
- Propensity score
- The conditional probability that a unit receives treatment given its observed covariates; adjusting for this single value removes bias attributable to all the measured covariates used to compute it.
Hand-Compute an Inverse-Propensity-Weighted Treatment Effect
A fully worked, paper-and-pencil exercise using a toy dataset of four units: two treated (outcomes 10 and 12, with estimated propensity scores 0.5 and 0.6) and two untreated (outcomes 6 and 8, with estimated propensity scores 0.4 and 0.5). The learner first computes the naive difference in means between treated and untreated outcomes, then computes the inverse-propensity-weighted estimate by dividing each treated outcome by its propensity score and each untreated outcome by one minus its propensity score, averaging, and comparing the two results by hand to see how reweighting shifts the estimated effect. No software or real patient data is used; every number is supplied and each arithmetic step is shown and checked.
Ready to test yourself?
5 questions on this module.