From 538f0332ec8978b1e21a534e4d7c5a23ed39904a Mon Sep 17 00:00:00 2001 From: Rishi Jumani Date: Tue, 29 Jun 2021 16:00:17 -0500 Subject: [PATCH] switch to tfcausalimpact --- README.md | 11 +++++++---- pycausalmatch/__version__.py | 4 ++-- pycausalmatch/main.py | 11 +++++------ requirements.txt | 2 +- setup.py | 6 +++--- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c3c56a6..1935a53 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,10 @@ intent of eventually deploying pipelines) The functionality that has been implemented so far is essentially a Python translation of the features available in the R library: https://github.com/klarsen1/MarketMatching (v.1.1.7 - as of Dec 2020), -which combines 2 packages: https://github.com/dafiti/causalimpact and https://github.com/DynamicTimeWarping/dtw-python +which combines 2 packages: https://github.com/WillianFuks/tfcausalimpact and https://github.com/DynamicTimeWarping/dtw-python + +(I switched to tfcausalimpact in v0.0.4, from pycausalimpact, which was available at https://github.com/dafiti/causalimpact, + but has now been removed) The DTW package is used for selection of most suitable control groups. @@ -42,7 +45,7 @@ rmm.inference(**kwargs) # returns ``` -This package has only been tested for **a single test market** (I will test it for multiple test markets soon) +This package has only been tested for **a single test market** (I will test it for multiple test markets soon). ## Example Use case @@ -71,7 +74,7 @@ under the notebooks/examples folder. I will keep updating this example as I deve - [ ] Add Streamlit and Dash app -- [ ] switch to https://github.com/WillianFuks/tfcausalimpact +- [x] switch to https://github.com/WillianFuks/tfcausalimpact - [ ] add remaining functionality of the R package @@ -88,7 +91,7 @@ Please make sure to update tests as appropriate. [MIT](https://choosealicense.com/licenses/mit/) -#### Project Organization +#### Project Organization (partially implemented) ------------ ├── LICENSE diff --git a/pycausalmatch/__version__.py b/pycausalmatch/__version__.py index b516cee..65967cb 100644 --- a/pycausalmatch/__version__.py +++ b/pycausalmatch/__version__.py @@ -1,5 +1,5 @@ -VERSION = (0, 0, 3) -__version__ = '.'.join([str(e) for e in VERSION]) \ No newline at end of file +VERSION = (0, 0, 4) +__version__ = '.'.join([str(e) for e in VERSION]) diff --git a/pycausalmatch/main.py b/pycausalmatch/main.py index 5887bbc..fd90aed 100644 --- a/pycausalmatch/main.py +++ b/pycausalmatch/main.py @@ -12,7 +12,7 @@ class R_MarketMatching(): - + """ TODO: @@ -364,7 +364,7 @@ def best_matches(data=None, markets_to_be_matched=None, id_variable=None, date_v else: #TODO add parallel execution print("Parallel execution has not been added yet - executing sequentially") - + for i in range(len(markets_to_be_matched)): dist_op = R_MarketMatching.calculate_distances(markets_to_be_matched, ip_df, id_variable, i, warping_limit, matches, dtw_emphasis @@ -456,7 +456,8 @@ def best_matches(data=None, markets_to_be_matched=None, id_variable=None, date_v def inference(matched_markets=None, bsts_modelargs=None, test_market=None, end_post_period=None, - alpha=0.05, prior_level_sd=0.01, control_matches=5, analyze_betas=False, nseasons=None + alpha=0.05, prior_level_sd=0.01, control_matches=5, analyze_betas=False, nseasons=None, + ci_fit_method = 'vi' ): @@ -558,7 +559,7 @@ def inference(matched_markets=None, bsts_modelargs=None, test_market=None, end_p #TODO add alpha=alpha, model.args=bsts_modelargs - impact = CausalImpact(ts, pre_period, post_period) + impact = CausalImpact(ts, pre_period, post_period, model_args={'fit_method': ci_fit_method}) #TODO implement analyze_betas = True if analyze_betas: @@ -586,5 +587,3 @@ def inference(matched_markets=None, bsts_modelargs=None, test_market=None, end_p print('Matching (pre) Period MAPE: ') return results - - diff --git a/requirements.txt b/requirements.txt index b28f3dc..819804d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ numpy>=1.18.1 pandas>=1.0.3 dtw-python==1.1.6 -pycausalimpact==0.0.14 +tfcausalimpact==0.0.5 diff --git a/setup.py b/setup.py index 81f45c6..42f7cce 100644 --- a/setup.py +++ b/setup.py @@ -3,11 +3,11 @@ with open("README.md", "r") as readme_file: readme = readme_file.read() -requirements = ["numpy>=1.18.1", "pandas>=1.0.3", "dtw-python==1.1.6", "pycausalimpact==0.0.14"] +requirements = ["numpy>=1.18.1", "pandas>=1.0.3", "dtw-python==1.1.6", "tfcausalimpact==0.0.5"] setup( name="pycausalmatch", - version="0.0.3", + version="0.0.4", author="Rishi Jumani", author_email="unbiased.modeler@gmail.com", description="Causal Impact of an intervention integrated with control group selection", @@ -21,4 +21,4 @@ "Programming Language :: Python :: 3.8", "License :: OSI Approved :: MIT License", ], -) \ No newline at end of file +)