GithubHelp home page GithubHelp logo

breakdawn / causal_impact Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tcassou/causal_impact

0.0 2.0 0.0 326 KB

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

Python 100.00%

causal_impact's Introduction

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

Simply install from pip:

pip install causal-impact

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.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

If you need access to the data behind the plots for further analysis, you can simply use the ci.result attribute (pandas.DataFrame object). Alternatively, you can also call

result = ci.run(return_df=True)

and skip the plotting step.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.