Skip to content

Commit

Permalink
Merge c0e79c7 into 18571f5
Browse files Browse the repository at this point in the history
  • Loading branch information
WillianFuks committed Apr 11, 2022
2 parents 18571f5 + c0e79c7 commit cd277d7
Show file tree
Hide file tree
Showing 4 changed files with 570 additions and 624 deletions.
2 changes: 1 addition & 1 deletion causalimpact/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.


__version__ = '0.0.10rc1'
__version__ = '0.0.10rc2'
39 changes: 34 additions & 5 deletions causalimpact/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,43 @@ class CausalImpact():
import tensorflow_probability as tfp
pre_y = data[:70, 0]
pre_X = data[:70, 1:]
obs_series = data.iloc[:, 0]
data = tfp.sts.regularize_series(data).astype('float32')
pre_period = ['20200101', '20200401']
post_period = ['20200402', '20200501']
obs_series = data.loc[:pre_period[1], 0]
local_linear = tfp.sts.LocalLinearTrend(observed_time_series=obs_series)
seasonal = tfp.sts.Seasonal(num_seasons=7, observed_time_series=obs_series)
model = tfp.sts.Sum([local_linear, seasonal], observed_time_series=obs_series)
ci = CausalImpact(data, pre_period, post_period, model=model,
model_args={'standardize': False})
print(ci.summary())
```
Notice that for custom models no assumptions are made about the input data used
to build the model. This can incur errors if `standardize` is set to True because
the model was built with the regular data and internally tfcausalimpact will
standardize it which removes the reference relatively to the model data. To avoid
that, all data processing must be held before calling causal impact. For instance:
```python
import tensorflow_probability as tfp
from causalimpact.misc import standardize
data = tfp.sts.regularize_series(data).astype('float32')
normed_data = standardize(data)[0]
pre_period = ['20200101', '20200401']
post_period = ['20200402', '20200501']
obs_series = normed_data.loc[:pre_period[1], 0]
local_linear = tfp.sts.LocalLinearTrend(observed_time_series=obs_series)
seasonal = tfp.sts.Seasonal(nseasons=7, observed_time_series=obs_series)
seasonal = tfp.sts.Seasonal(num_seasons=7, observed_time_series=obs_series)
model = tfp.sts.Sum([local_linear, seasonal], observed_time_series=obs_series)
ci = CausalImpact(data, pre_period, post_period, model=model)
ci = CausalImpact(data, pre_period, post_period, model=model,
model_args={'standardize': True})
print(ci.summary())
```
"""
Expand Down
1,149 changes: 532 additions & 617 deletions notebooks/getting_started.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: Unix',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
Expand Down

0 comments on commit cd277d7

Please sign in to comment.