{"id":31265466,"url":"https://github.com/willianfuks/tfcausalimpact","last_synced_at":"2025-10-07T03:34:40.842Z","repository":{"id":40541372,"uuid":"288209400","full_name":"WillianFuks/tfcausalimpact","owner":"WillianFuks","description":"Python Causal Impact Implementation Based on Google's R Package. Built using TensorFlow Probability.","archived":false,"fork":false,"pushed_at":"2025-01-13T14:42:12.000Z","size":8498,"stargazers_count":647,"open_issues_count":46,"forks_count":75,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-09-23T14:50:28.197Z","etag":null,"topics":["causal-inference","causalimpact","python","tensorflow-probability"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WillianFuks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-08-17T14:57:52.000Z","updated_at":"2025-09-23T07:53:39.000Z","dependencies_parsed_at":"2024-05-06T19:55:31.842Z","dependency_job_id":"c76b50a7-a39e-446d-943b-02825709cc4e","html_url":"https://github.com/WillianFuks/tfcausalimpact","commit_stats":{"total_commits":39,"total_committers":3,"mean_commits":13.0,"dds":0.05128205128205132,"last_synced_commit":"edc284024a601204c16048ada9a6f7df17bbee6c"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/WillianFuks/tfcausalimpact","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillianFuks%2Ftfcausalimpact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillianFuks%2Ftfcausalimpact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillianFuks%2Ftfcausalimpact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillianFuks%2Ftfcausalimpact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WillianFuks","download_url":"https://codeload.github.com/WillianFuks/tfcausalimpact/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillianFuks%2Ftfcausalimpact/sbom","scorecard":{"id":151503,"data":{"date":"2025-08-11","repo":{"name":"github.com/WillianFuks/tfcausalimpact","commit":"3688b83e9f52909c4ab0b8c4f2d885bb4402fbfd"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":2,"reason":"Found 7/28 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/publish-pypi.yml:1","Warn: no topLevel permission defined: .github/workflows/run-CI.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-pypi.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/publish-pypi.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-pypi.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/publish-pypi.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish-pypi.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/publish-pypi.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-CI.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/run-CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-CI.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/run-CI.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-CI.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/run-CI.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-CI.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/WillianFuks/tfcausalimpact/run-CI.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/publish-pypi.yml:22","Warn: pipCommand not pinned by hash: .github/workflows/publish-pypi.yml:23","Warn: pipCommand not pinned by hash: .github/workflows/run-CI.yml:45","Warn: pipCommand not pinned by hash: .github/workflows/run-CI.yml:46","Info:   0 out of   5 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   4 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/publish-pypi.yml:9"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 21 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T10:48:49.988Z","repository_id":40541372,"created_at":"2025-08-16T10:48:49.989Z","updated_at":"2025-08-16T10:48:49.989Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278716548,"owners_count":26033495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["causal-inference","causalimpact","python","tensorflow-probability"],"created_at":"2025-09-23T14:38:38.937Z","updated_at":"2025-10-07T03:34:40.837Z","avatar_url":"https://github.com/WillianFuks.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tfcausalimpact\n[![Build Status](https://travis-ci.com/WillianFuks/tfcausalimpact.svg?branch=master)](https://travis-ci.com/WillianFuks/tfcausalimpact) [![Coverage Status](https://coveralls.io/repos/github/WillianFuks/tfcausalimpact/badge.svg?branch=master)](https://coveralls.io/github/WillianFuks/tfcausalimpact?branch=master) [![GitHub license](https://img.shields.io/github/license/WillianFuks/tfcausalimpact.svg)](https://github.com/WillianFuks/tfcausalimpact/blob/master/LICENSE) [![PyPI version](https://badge.fury.io/py/tfcausalimpact.svg)](https://badge.fury.io/py/tfcausalimpact) [![Pyversions](https://img.shields.io/pypi/pyversions/tfcausalimpact.svg)](https://pypi.python.org/pypi/tfcausalimpact)\n\nGoogle's [Causal Impact](https://github.com/google/CausalImpact) Algorithm Implemented on Top of [TensorFlow Probability](https://github.com/tensorflow/probability).\n\n## How It Works\nThe algorithm basically fits a [Bayesian structural](https://en.wikipedia.org/wiki/Bayesian_structural_time_series) model on past observed data to make predictions on what future data would look like. Past data comprises everything that happened before an intervention (which usually is the changing of a variable as being present or not, such as a marketing campaign that starts to run at a given point). It then compares the counter-factual (predicted) series against what was really observed in order to extract statistical conclusions.\n\nRunning the model is quite straightforward, it requires the observed data `y`, covariates `X` that helps the model through a linear regression, a `pre-period` interval that selects everything that happened before the intervention and a `post-period` with data after the \"impact\" happened.\n\nPlease refer to this medium [post](https://towardsdatascience.com/implementing-causal-impact-on-top-of-tensorflow-probability-c837ea18b126) for more on this subject.\n\n## Installation\n\n    pip install tfcausalimpact\n\n## Requirements\n\n - python{3.7, 3.8, 3.9, 3.10, 3.11}\n - matplotlib\n - jinja2\n - tensorflow\u003e=2.10.0\n - tensorflow_probability\u003e=0.18.0\n - pandas \u003e= 1.3.5\n\n\n## Getting Started\n\nWe recommend this [presentation](https://www.youtube.com/watch?v=GTgZfCltMm8) by Kay Brodersen (one of the creators of the Causal Impact in R).\n\nWe also created this introductory [ipython notebook](https://github.com/WillianFuks/tfcausalimpact/blob/master/notebooks/getting_started.ipynb) with examples of how to use this package.\n\nThis medium [article](https://towardsdatascience.com/implementing-causal-impact-on-top-of-tensorflow-probability-c837ea18b126) also offers some ideas and concepts behind the library.\n\n### Example\n\nHere's a simple example (which can also be found in the original Google's R implementation) running in Python:\n\n```python\nimport pandas as pd\nfrom causalimpact import CausalImpact\n\n\ndata = pd.read_csv('https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/tests/fixtures/arma_data.csv')[['y', 'X']]\ndata.iloc[70:, 0] += 5\n\npre_period = [0, 69]\npost_period = [70, 99]\n\nci = CausalImpact(data, pre_period, post_period)\nprint(ci.summary())\nprint(ci.summary(output='report'))\nci.plot()\n```\n\nSummary should look like this:\n\n```\nPosterior Inference {Causal Impact}\n                          Average            Cumulative\nActual                    125.23             3756.86\nPrediction (s.d.)         120.34 (0.31)      3610.28 (9.28)\n95% CI                    [119.76, 120.97]   [3592.67, 3629.06]\n\nAbsolute effect (s.d.)    4.89 (0.31)        146.58 (9.28)\n95% CI                    [4.26, 5.47]       [127.8, 164.19]\n\nRelative effect (s.d.)    4.06% (0.26%)      4.06% (0.26%)\n95% CI                    [3.54%, 4.55%]     [3.54%, 4.55%]\n\nPosterior tail-area probability p: 0.0\nPosterior prob. of a causal effect: 100.0%\n\nFor more details run the command: print(impact.summary('report'))\n```\n\nAnd here's the plot graphic:\n\n![alt text](https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/notebooks/tfcausal_plot_example.png)\n\n## Google R Package vs TensorFlow Python\n\nBoth packages should give equivalent results. Here's an example using the `comparison_data.csv` dataset available in the `fixtures` folder. When running CausalImpact in the original R package, this is the result:\n\n### R\n\n```{r}\ndata = read.csv.zoo('comparison_data.csv', header=TRUE)\npre.period \u003c- c(as.Date(\"2019-04-16\"), as.Date(\"2019-07-14\"))\npost.period \u003c- c(as.Date(\"2019-07-15\"), as.Date(\"2019-08-01\"))\nci = CausalImpact(data, pre.period, post.period)\n```\n\nSummary results:\n\n```\nPosterior inference {CausalImpact}\n\n                         Average          Cumulative\nActual                   78574            1414340\nPrediction (s.d.)        79232 (736)      1426171 (13253)\n95% CI                   [77743, 80651]   [1399368, 1451711]\n\nAbsolute effect (s.d.)   -657 (736)       -11831 (13253)\n95% CI                   [-2076, 832]     [-37371, 14971]\n\nRelative effect (s.d.)   -0.83% (0.93%)   -0.83% (0.93%)\n95% CI                   [-2.6%, 1%]      [-2.6%, 1%]\n\nPosterior tail-area probability p:   0.20061\nPosterior prob. of a causal effect:  80%\n\nFor more details, type: summary(impact, \"report\")\n```\n\nAnd correspondent plot:\n\n![alt text](https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/notebooks/R/comparison/Rplot.png)\n\n### Python\n\n```python\nimport pandas as pd\nfrom causalimpact import CausalImpact\n\n\ndata = pd.read_csv('https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/tests/fixtures/comparison_data.csv', index_col=['DATE'])\npre_period = ['2019-04-16', '2019-07-14']\npost_period = ['2019-7-15', '2019-08-01']\nci = CausalImpact(data, pre_period, post_period, model_args={'fit_method': 'hmc'})\n```\n\nSummary is:\n\n```\nPosterior Inference {Causal Impact}\n                          Average            Cumulative\nActual                    78574.42           1414339.5\nPrediction (s.d.)         79282.92 (727.48)  1427092.62 (13094.72)\n95% CI                    [77849.5, 80701.18][1401290.94, 1452621.31]\n\nAbsolute effect (s.d.)    -708.51 (727.48)   -12753.12 (13094.72)\n95% CI                    [-2126.77, 724.92] [-38281.81, 13048.56]\n\nRelative effect (s.d.)    -0.89% (0.92%)     -0.89% (0.92%)\n95% CI                    [-2.68%, 0.91%]    [-2.68%, 0.91%]\n\nPosterior tail-area probability p: 0.16\nPosterior prob. of a causal effect: 84.12%\n\nFor more details run the command: print(impact.summary('report'))\n```\n\nAnd plot:\n\n![alt text](https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/notebooks/R/comparison/Pythonplot.png)\n\nBoth results are equivalent.\n\n## Performance\n\nThis package uses as default the [`Variational Inference`](https://en.wikipedia.org/wiki/Variational_Bayesian_methods) method from `TensorFlow Probability` which is faster and should work for the most part. Convergence can take somewhere between 2~3 minutes on more complex time series. You could also try running the package on top of GPUs to see if results improve.\n\nIf, on the other hand, precision is the top requirement when running causal impact analyzes, it's possible to switch algorithms by manipulating the input arguments like so:\n\n```python\nci = CausalImpact(data, pre_period, post_period, model_args={'fit_method': 'hmc'})\n```\n\nThis will make usage of the algorithm [`Hamiltonian Monte Carlo`](https://en.wikipedia.org/wiki/Hamiltonian_Monte_Carlo) which is State-of-the-Art for finding the Bayesian posterior of distributions. Still, keep in mind that on complex time series with thousands of data points and complex modeling involving various seasonal components this optimization can take 1 hour or even more to complete (on a GPU). Performance is sacrificed in exchange for better precision.\n\n## Bugs \u0026 Issues\n\nIf you find bugs or have any issues while running this library please consider opening an [`Issue`](https://github.com/WillianFuks/tfcausalimpact/issues) with a complete description and reproductible environment so we can better help you solving the problem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillianfuks%2Ftfcausalimpact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillianfuks%2Ftfcausalimpact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillianfuks%2Ftfcausalimpact/lists"}