Skip to content

Commit

Permalink
switch to tfcausalimpact
Browse files Browse the repository at this point in the history
  • Loading branch information
rj678 committed Jun 29, 2021
1 parent b5119e2 commit 538f033
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pycausalmatch/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@



VERSION = (0, 0, 3)
__version__ = '.'.join([str(e) for e in VERSION])
VERSION = (0, 0, 4)
__version__ = '.'.join([str(e) for e in VERSION])
11 changes: 5 additions & 6 deletions pycausalmatch/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class R_MarketMatching():

"""
TODO:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
):


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -586,5 +587,3 @@ def inference(matched_markets=None, bsts_modelargs=None, test_market=None, end_p
print('Matching (pre) Period MAPE: ')

return results


2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="Causal Impact of an intervention integrated with control group selection",
Expand All @@ -21,4 +21,4 @@
"Programming Language :: Python :: 3.8",
"License :: OSI Approved :: MIT License",
],
)
)

0 comments on commit 538f033

Please sign in to comment.