Book Image

Causal Inference and Discovery in Python

By : Aleksander Molak
4.7 (9)
Book Image

Causal Inference and Discovery in Python

4.7 (9)
By: Aleksander Molak

Overview of this book

Causal methods present unique challenges compared to traditional machine learning and statistics. Learning causality can be challenging, but it offers distinct advantages that elude a purely statistical mindset. Causal Inference and Discovery in Python helps you unlock the potential of causality. You’ll start with basic motivations behind causal thinking and a comprehensive introduction to Pearlian causal concepts, such as structural causal models, interventions, counterfactuals, and more. Each concept is accompanied by a theoretical explanation and a set of practical exercises with Python code. Next, you’ll dive into the world of causal effect estimation, consistently progressing towards modern machine learning methods. Step-by-step, you’ll discover Python causal ecosystem and harness the power of cutting-edge algorithms. You’ll further explore the mechanics of how “causes leave traces” and compare the main families of causal discovery algorithms. The final chapter gives you a broad outlook into the future of causal AI where we examine challenges and opportunities and provide you with a comprehensive list of resources to learn more. By the end of this book, you will be able to build your own models for causal inference and discovery using statistical and machine learning techniques as well as perform basic project assessment.
Table of Contents (21 chapters)
Part 1: Causality – an Introduction
Part 2: Causal Inference
Part 3: Causal Discovery

Starting simple – observational data and linear regression

In previous chapters, we discussed the concept of association. In this section, we’ll quantify associations between variables using a regression model. We’ll see the geometrical interpretation of this model and demonstrate that regression can be performed in an arbitrary direction. For the sake of simplicity, we’ll focus our attention on linear cases. Let’s start!

Linear regression

Linear regression is a basic data-fitting algorithm that can be used to predict the expected value of a dependent (target) variable, <mml:math xmlns:mml="" xmlns:m=""><mml:mi>Y</mml:mi></mml:math>, given values of some predictor(s), <mml:math xmlns:mml="" xmlns:m=""><mml:mi>X</mml:mi></mml:math>. Formally, this is written as <math xmlns=""><mrow><mrow><msub><mover><mi>Y</mi><mo stretchy="true">ˆ</mo></mover><mrow><mi>X</mi><mo>=</mo><mi>x</mi></mrow></msub><mo>=</mo><mi>E</mi><mfenced open="[" close="]"><mrow><mi>Y</mi><mo>|</mo><mi>X</mi><mo>=</mo><mi>x</mi></mrow></mfenced></mrow></mrow></math>.

In the preceding formula, <mml:math xmlns:mml="" xmlns:m=""><mml:msub><mml:mrow><mml:mover accent="true"><mml:mrow><mml:mi>Y</mml:mi></mml:mrow><mml:mo>^</mml:mo></mml:mover></mml:mrow><mml:mrow><mml:mi>X</mml:mi><mml:mo>=</mml:mo><mml:mi>x</mml:mi></mml:mrow></mml:msub></mml:math> is the predicted value of <mml:math xmlns:mml="" xmlns:m=""><mml:mi>Y</mml:mi></mml:math> given that <mml:math xmlns:mml="" xmlns:m=""><mml:mi>X</mml:mi></mml:math> takes the value(s) <mml:math xmlns:mml="" xmlns:m=""><mml:mi>x</mml:mi></mml:math>. <mml:math xmlns:mml="" xmlns:m=""><mml:mi>E</mml:mi><mml:mo>[</mml:mo><mml:mo>.</mml:mo><mml:mo>]</mml:mo></mml:math> is the expected value operator. Note that <mml:math xmlns:mml="" xmlns:m=""><mml:mi>X</mml:mi></mml:math> can be multidimensional. In such cases, <mml:math xmlns:mml="" xmlns:m=""><mml:mi>X</mml:mi></mml:math> is usually represented as a matrix, X, with shape <mml:math xmlns:mml="" xmlns:m=""><mml:mi>N</mml:mi><mml:mo>×</mml:mo><mml:mi>D</mml:mi></mml:math>, where <mml:math xmlns:mml="" xmlns:m=""><mml:mi>N</mml:mi></mml:math> is the number of observations and <mml:math xmlns:mml="" xmlns:m=""><mml:mi>D</mml:mi></mml:math> is the dimensionality of <mml:math xmlns:mml="" xmlns:m=""><mml:mi>X</mml:mi></mml:math> (the number of...