← Back

Why Causal Inference Is the Missing Piece in Most ML Systems


Machine learning has become extraordinarily good at one thing: prediction. Given historical data, modern models can forecast churn, detect fraud, recommend products, and classify images with superhuman accuracy.

But prediction is not causation. And when you need to make decisions — not just predictions — this distinction becomes critical.

The Prediction vs. Causation Gap

Imagine you’re a data scientist at an e-commerce company. Your model predicts that users who see a particular banner ad are 40% more likely to purchase. Should you show the banner to everyone?

Not necessarily. Users who notice the banner may already be in a high-intent state. The banner correlates with purchase, but it might not cause it. Showing the banner to low-intent users could be wasteful or even counterproductive.

This is the core problem causal inference addresses: what is the effect of an intervention? In formal terms, what is E[Y | do(X=x)] — the expected outcome if we set X to x — versus E[Y | X=x] — the expected outcome when we merely observe X equal to x?

The Do-Calculus and Structural Causal Models

Judea Pearl’s do-calculus gives us a formal language for causal reasoning. The key objects are:

  • Structural Causal Model (SCM) — a set of equations describing how each variable is generated from its parents and noise
  • Directed Acyclic Graph (DAG) — the graph of causal relationships
  • Interventiondo(X=x) surgically sets X, severing its connection to its causes
import networkx as nx
import matplotlib.pyplot as plt

# Simple causal graph: Ad → Purchase ← Intent → Ad
G = nx.DiGraph()
G.add_edges_from([
    ("Intent", "Purchase"),
    ("Intent", "Ad"),
    ("Ad", "Purchase"),
])

To identify a causal effect from observational data, we need to block backdoor paths — confounding paths that flow against the causal direction. The backdoor criterion tells us when a set of variables Z is sufficient to adjust for.

Practical Tools in Python

Double Machine Learning (DoubleML)

DoubleML uses Neyman orthogonality to estimate treatment effects while controlling for high-dimensional confounders using any ML model:

from doubleml import DoubleMLPLR
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier

# Partially Linear Regression
dml = DoubleMLPLR(
    obj_dml_data,
    ml_l=RandomForestRegressor(n_estimators=200),
    ml_m=RandomForestClassifier(n_estimators=200),
)
dml.fit()
print(dml.summary)

The beauty of DoubleML: you can use powerful ML models for nuisance functions without worrying about regularisation bias in the treatment effect estimate.

CausalML for Uplift Modelling

Uplift modelling — estimating individual treatment effects (ITEs) — is the causal cousin of predictive modelling. CausalML provides a suite of algorithms:

from causalml.inference.tree import UpliftTreeClassifier

model = UpliftTreeClassifier(
    control_name='control',
    max_depth=5,
    min_samples_leaf=100,
)
model.fit(X_train, treatment_train, y_train)
uplift = model.predict(X_test)

When Should You Use Causal Methods?

Use causal inference when:

  1. You need to evaluate interventions — pricing changes, UI experiments, policy decisions
  2. RCTs aren’t feasible — ethical constraints, cost, or timeline prevent randomisation
  3. You need to personalise interventions — individual-level effects (ITE/HTE), not just average effects
  4. Your model will be used to make decisions — not just to generate predictions

Stick with predictive ML when you only need to rank or score, not decide.

A Word on Assumptions

Causal inference is not magic. Every causal claim rests on assumptions — often untestable from data alone:

  • Unconfoundedness — no unmeasured confounders
  • Positivity — every unit has some probability of receiving each treatment level
  • SUTVA — stable unit treatment value assumption; no interference between units

Violating these silently produces biased estimates. Always reason carefully about your causal graph before applying these methods, and be honest about what you cannot verify.

Closing Thoughts

The field is converging: causal machine learning, combining the flexibility of ML with the rigour of causal reasoning, is becoming the standard toolkit for data scientists who influence business decisions. If your work involves A/B testing analysis, policy evaluation, or personalisation at scale, it’s worth investing time here.

I’m actively building a causal inference toolkit — feel free to open an issue or contribute.