Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Correlation vs. Causation in Feature Engineering

Hello! Welcome to the fourth lesson in our course on advanced feature engineering.

Introduction

In our last lesson, we used information theory to quantify the strength of statistical relationships between features and a target variable. We saw that mutual information provides a powerful, model-agnostic way to measure feature relevance, capturing even complex, non-linear patterns.

However, a strong statistical relationship—whether measured by correlation or mutual information—is not the end of the story. Today, we confront a fundamental concept in data science and statistics: the difference between correlation and causation.

The learning outcome for this lesson is to explain the difference between correlation and causation in the context of feature creation and its implications for model interpretability. Misinterpreting a correlation as a causal link is one of the most common and dangerous errors in applied machine learning, leading to flawed business strategies and models that fail unexpectedly. By the end of this lesson, you will be able to articulate why this distinction is critical, identify situations where predictive models can be misleading, and understand the conceptual frameworks used to reason about cause and effect.

Machine Learning vs. Causality Visual Comparison
This diagram contrasts the typical machine learning approach with a causal one. On the left, 'Machine Learning' models find correlational patterns between a set of inputs and an output. On the right, 'Causality' aims to map the underlying structure of how variables influence one another.

Prediction vs. Intervention: Why the Difference Matters

Most machine learning models are designed for prediction. For this task, correlation is often sufficient. If a feature consistently co-occurs with an outcome, it has predictive power, regardless of the underlying reason. However, the moment we want to use a model to guide intervention—to make a decision intended to change an outcome—we step into the world of causation.

The following video from an MIT course on Machine Learning for Healthcare provides an excellent introduction to this distinction.

14. Causal Inference, Part 1

Let's watch the beginning of the lecture 'Causal Inference, Part 1' by David Sontag. It clearly frames why correlation is not enough when we move from passive prediction to active intervention, using high-stakes examples from medicine.

Please watch the video from 00:15 to 06:47. Focus on: The distinction between purely predictive questions and causal questions (00:15 - 01:40). The examples (gastric bypass surgery, cancer treatment) that illustrate how a predictive model, interpreted causally, could lead to dangerous and incorrect actions (01:40 - 06:47).

As the video illustrates, a model might learn that patients who received a certain surgery have better outcomes. This is a correlation. But does this mean we should give that surgery to more people to cause better outcomes? Not necessarily. Perhaps the surgery was only given to patients who were already healthier, a classic case of a confounding variable.

How Predictive Models Get Deceived

To understand why even sophisticated models like XGBoost or neural networks confuse correlation with causation, we need to examine how they learn. These models are powerful function approximators, designed to find patterns in data that minimize a loss function. They do not inherently model the data-generating process.

This article, co-authored by prominent researchers at Microsoft, uses a practical business example to show exactly how interpreting a predictive model's outputs can lead to incorrect causal conclusions.

Be Careful When Interpreting Predictive Models in Search of Causal Insights

The article 'Be Careful When Interpreting Predictive Models in Search of Causal Insights' provides a clear, code-driven explanation of this problem. It uses a customer retention scenario to demonstrate how a model can learn counter-intuitive relationships.

Please read the first few sections of the article, from the beginning down to the heading 'The challenges of estimating causal effects'. Pay close attention to: The distinction between a prediction task and a causal task. The surprising findings from the XGBoost model (e.g., more bugs reported leads to higher renewal probability). The explanation for these findings: an unmeasured confounding feature called 'Product Need'. The causal graph is a key visualization here.

The key takeaway is that the model is not "wrong"; it is correctly identifying a pattern in the training data. High-usage customers (who have high "product need") are both more likely to report bugs and more likely to renew. The model finds the correlation between "bugs reported" and "renewal" because it acts as a proxy for the unobserved confounder, "product need".

Intervening based on this model would be a disaster. Telling the engineering team to introduce more bugs to increase retention is nonsensical, yet it's the logical conclusion if one naively interprets the model's feature importance as causal.

A Framework for Thinking Causally

To move beyond simple correlation, we need a more structured way to think about cause and effect. The pioneering work of computer scientist Judea Pearl provides such a framework.

Simpson's Paradox: The Ultimate Warning

One of the most striking illustrations of the pitfalls of relying on correlation is Simpson's Paradox, where a trend that appears in different groups of data disappears or reverses when these groups are combined.

Judea Pearl: "Interpretability and explainability from a causal lens"

Let's watch a segment from a talk by Judea Pearl himself, where he uses Simpson's Paradox to show the fundamental difference between seeing (correlation) and doing (intervention).

Watch the segment from 00:36:25 to 00:42:32. Pearl discusses a hypothetical dataset where exercise appears positively correlated with cholesterol in the aggregate data, but negatively correlated within every age group. This starkly demonstrates how ignoring a confounding variable (age) can lead to the completely wrong conclusion.

The paradox highlights a crucial point: the decision of whether to aggregate data or partition it depends on your causal assumptions about the world. Statistics alone cannot tell you which view (the aggregated or the partitioned) is correct for decision-making.

The Ladder of Causation

Pearl organizes causal reasoning into a three-level hierarchy, which he calls the "Ladder of Causation." This is a powerful mental model for classifying the types of questions we can ask.

Judea Pearl: "Interpretability and explainability from a causal lens"

Let's continue with Judea Pearl's talk as he outlines his 'Ladder of Causation'.

Watch the segment from 00:23:17 to 00:36:25. Focus on understanding the three distinct levels: Association (Seeing): P(Y|X). This is the domain of standard machine learning. It involves finding patterns in data. Intervention (Doing): P(Y|do(X)). This level asks what would happen if we actively change something. Counterfactuals (Imagining): P(Y_x|X=x', Y=y'). This addresses retrospective questions, like 'What would have happened if...?'

Most of your experience with machine learning likely falls on the first rung. The central theme of this lesson is that you cannot answer questions from a higher rung using only tools from a lower rung. To answer a question about an intervention (do(X)), you need more than just observational data and correlations (P(Y|X)). You need a causal model.

Quantifying Causal Effects: A Practical Example

So, how do we estimate the true effect of an intervention? The Rubin Causal Model provides a mathematical framework using the concept of potential outcomes. For a binary treatment T (e.g., took a drug or didn't), we imagine that each individual i has two potential outcomes:

  • : The outcome if they receive the treatment.
  • : The outcome if they do not receive the treatment.

The fundamental problem of causal inference is that we only ever observe one of these for any given individual. The unobserved one is the counterfactual.

The causal effect for an individual is . The Average Treatment Effect (ATE) is the average of this difference over the entire population: .

The following video walks through a brilliant numerical example showing how a naive, correlation-based calculation gives the wrong answer, while a proper calculation of the ATE gives the right one.

14. Causal Inference, Part 1

Let's return to the MIT lecture to see how these concepts are put into practice with a concrete numerical example. This will solidify the difference between a naive estimate and the true causal effect.

Please watch from 00:09:28 to 00:38:47. The first part (until 24:36) introduces the notation of potential outcomes. The second part (from 24:36) is a hands-on exercise with a small dataset. I encourage you to pause the video and try the calculations yourself before the presenter reveals the answers. You'll compute: The naive difference: E[Y|T=B] - E[Y|T=A] The true Average Treatment Effect: E[Y(B)] - E[Y(A)]

This exercise demonstrates that E[Y|T=1] - E[Y|T=0] is not the same as E[Y(1) - Y(0)]. The first is a simple correlation, while the second is the causal quantity we actually care about. They are only equal in a randomized controlled trial. In observational data, they can differ wildly due to confounding.

Interview & Business Context Alert

Question: "Our model shows that customers who receive larger discounts are churning at a higher rate. Should we stop giving discounts?"

Your Analysis: "This is a classic correlation-versus-causation scenario. The model is likely picking up on a confounding factor. For instance, the sales team may be giving the largest discounts to customers they've already identified as being at high risk of churning, in a last-ditch effort to keep them. In this case, the high churn rate isn't caused by the discount; rather, the propensity to churn is a common cause of both receiving a large discount and actually churning.

Acting on this correlation by eliminating discounts would be a mistake. It could even make the problem worse. To understand the true effect of discounts, we can't rely on this predictive model's feature importance. We would need to either run a controlled experiment (an A/B test where we randomize who gets a discount) or use causal inference methods on our observational data to try and control for the confounding factors that influence both the discount amount and the decision to churn."

Conclusion

This lesson drew a critical line in the sand between two related but distinct concepts. Understanding this boundary is a hallmark of a sophisticated data scientist who can build not just predictive models, but also reliable systems for decision-making.

Key Takeaways:

  • Correlation finds associations, while causation explains mechanisms. Standard ML excels at the former.
  • Interpreting a predictive model's feature importance as a guide for policy or intervention is a causal claim that is usually not justified.
  • Confounding variables are hidden common causes that create spurious correlations, misleading predictive models.
  • Frameworks like Pearl's Ladder of Causation and the Rubin Causal Model (Potential Outcomes) provide the conceptual and mathematical language to reason about cause and effect.
  • The causal effect (E[Y(1) - Y(0)]) is not the same as the observed difference in outcomes (E[Y|T=1] - E[Y|T=0]) unless the data comes from a randomized experiment.

What's Next?

We've now established the crucial difference between statistical patterns and causal mechanisms. This provides a critical lens through which to view all feature engineering. In our next lesson, we will return to the practical task of feature creation, exploring non-linear feature generation techniques like radial basis functions and spline transformations. While these methods don't automatically solve the causation problem, they allow our models to capture more complex relationships in the data, which is a necessary step toward building more nuanced and powerful models.

Can't find a good explanation? Sign up and we'll make it for you

Sign up