2 years ago
#73078

NSaibot
ValueError: Customized Linear Regression Models must have total points equal to pre_data and post_data points and same number of covariates
I could really use some help. I am attempting to create a simple customized model from tfcausalimpact in a Jupyter notebook. The default model for tfcausalimpact was not generalizing very well, so I decided to go this route with a customized model.
I have 24 months that I am using for pre-data, and 12 months for post-data. In the end I have a [36,0] matrix, with the dates as an index and the number of things I am counting as a column.
After running this block of code, I receive an error: ValueError: Customized Linear Regression Models must have total points equal to pre_data and post_data points and same number of covariates. Input design_matrix shape was (36, 0) and expected (149, 0) instead.
Here is a snapshot of the data I am using, the dates are the index, the values are a column:
pre_period = ['20180402', '20200302']
post_period = ['20200406', '20210301']
normed_data, _ = standardize(data1.astype(np.float32))
normed_data=normed_data.sort_index()
obs_data = normed_data.loc[:'2021-03-01'].astype(np.float32)
obs_data=obs_data.asfreq('M')
design_matrix = pd.concat(
[normed_data.loc[pre_period[0]: pre_period[1]], normed_data.loc[post_period[0]: post_period[1]]]
).astype(np.float32).iloc[:, 1:]
linear_level = tfp.sts.LocalLinearTrend(observed_time_series=obs_data)
linear_reg = tfp.sts.LinearRegression(design_matrix=design_matrix)
month_season = tfp.sts.Seasonal(num_seasons=4, num_steps_per_season=1, observed_time_series=obs_data, name='Month')
year_season = tfp.sts.Seasonal(num_seasons=52, observed_time_series=obs_data, name='Year')
model = tfp.sts.Sum([linear_level, linear_reg], observed_time_series=obs_data)
ci1 = CausalImpact(data1, pre_period, post_period, model=model)
python
tensorflow
jupyter-notebook
time-series
linear-regression
0 Answers
Your Answer