A introduction to causal inference using common tools from the python data stack
You'll need graphviz
for our first exercise notebook, to visualize causal graphs.
- Linux:
- Depending on your distro, here are the possible commands
- MacOS:
- You can easily install it via homebrew:
brew install graphviz
- You can easily install it via homebrew:
- Windows:
- The graphviz.org website has convenient installers for you
In your terminal, use git
to clone the repo to your machine.
git clone [email protected]:ronikobrosly/causal_inference_intro.git
If you are less comfortable with git
, there is an easy alternative: You can simply download a zip file of it here :)
Now that you've installed graphviz
and cloned the repo locally, you'll need to ensure you have a working python environment set up. There are two ways you can go about doing this, shown as Options 1 and 2 below. Option 1 is the preferred method, as it is more likely to work across all platforms.
If you already have installed and are using Anaconda python on your laptop please use Option 2.
This tutorial requires python version 3.9
for the notebook exercises to properly work.
Create a new virtual environment for this tutorial. You can do this a number of ways but one of the simpler involves the use of the virtualenv
python package. If you are a Windows or Linux user, please use this guide. If you are a MacOS user you can follow this guide.
Name your environment causal_modeling
"Activate" this environment (see the above guide) and then run the following command in the root folder of this repo:
pip install -r requirement.txt
This will install all the necessary packages for the tutorial.
As an optional step, you can try to run the check_environment.py
file (in the root folder of the repo)
while within your virtual environment. You can do so by running python check_environment.py
in your terminal. It will alert you if you're missing any required python packages.
If you do not already have the Anaconda distribution of Python 3, please install it.
The next step depends on what platform you are using: 1) Mac and Linux vs 2) Windows
Mac and Linux:
You can then use the conda
tool in your terminal to install the necessary packages via this command:
conda env create -f conda_env_mac.yml
"Activate" the new environment via:
conda activate causal_modeling
As an optional step, you can try to run the check_environment.py
file (in the root folder of the repo)
while within your virtual environment. You can do so by running python check_environment.py
in your terminal. It will alert you if you're missing any required python packages.
Windows:
You can then use the conda
tool in your terminal to install the necessary packages via this command:
conda env create -f conda_env_windows.yml
"Activate" the new environment via:
conda activate causal_modeling
As an optional step, you can try to run the check_environment.py
file (in the root folder of the repo)
while within your virtual environment. You can do so by running python check_environment.py
in your terminal. It will alert you if you're missing any required python packages.
If the above Anaconda methods do not work:
You may have to create your own python 3.9.x environment using the conda
command:
conda create --name causal_modeling python=3.9
"Activate" the new environment via:
conda activate causal_modeling
And then you'll pip install all dependencies within this environment
pip install -r requirements.txt
Once the above is complete, you'll need to run the following commands:
python -m ipykernel install --user --name causal_modeling --display-name "Python (causal_modeling)"
In the terminal, execute jupyter lab
.
Navigate to the notebooks
directory and open your notebook of choice. You will probably be asked which environment you would like to use with the notebook. Select the Python (causal_modeling)
environment you created in the step above.
I would like to like to acknowledgement the following individuals for creating public causal inference materials that were useful in the creation of this tutorial:
- Konstantinos Papadopoulos @ Analytics Mayhem
- Ramin Ghelichi @ Wayfair
I love would to hear your feedback on these tutorial materials! Please send your comments to [email protected].