/causal_impact

Python package for causal inference using Bayesian structural time-series models.

Primary LanguagePython

Python Causal Impact

Build Status

Work In Progress

Causal inference using Bayesian structural time-series models. This package aims at defining a python equivalent of the R CausalImpact package by Google. Please refer to the package itself, its documentation or the related publication (Brodersen et al., Annals of Applied Statistics, 2015) for more information.

Setup

Preferably use a virtual environment:

git clone git@github.com:tcassou/causal_impact
cd causal_impact
virtualenv .venv
. .venv/bin/activate
pip install -r requirements.txt

Example

Suppose we have a DataFrame data recording daily measures for three different markets y, x1 and x2, for t = 0..365). The y time series in data is the one we will be modeling, while other columns (x1 and x2 here) will be used as a set of control time series.

>>> data
      y       x1      x2
  0   1735.01 1014.44 1005.87
  1   1709.54 1012.63 1008.18
  2   1772.95 1039.04 1024.21
...   ...     ...     ...

At t = date_inter = 280, a marketing campaing (the intervention) is run for market y. We want to understand the impact of that campaign on our measure.

from causal_impact import CausalImpact

ci = CausalImpact(data, date_inter)
ci.run()
ci.plot()

After fitting the model, and estimating what the y time series would have been without any intervention, this will typically produce the following plots: Impact Plot

Issues and improvements

As mentioned above, this package is still being developed. Feel free to contribute through github by sending pull requests or reporting issues.