viera
viera

Reputation: 61

Causal Impact Summary - AttributeError: 'NoneType' object has no attribute 'loc'

anyone can help? Here are my codes.

df_ci = pd.DataFrame(df_ig.groupby(['Tanggal'])['INTERACTIONS IG'].sum())
df_ci

It is what the dataframe looks like.

INTERACTIONS IG

Tanggal

2021-12-02 74.0

2021-12-03 326.0

2021-12-14 51.0

... ...

2022-05-30 80.0

2022-05-31 270.0

Then, i used Causal Impact packages.

pre = ['2021-12-02', '2022-02-28']  
post = ['2022-03-01', '2022-05-31'] 
from causalimpact import CausalImpact
ci = CausalImpact(df_ci["INTERACTIONS IG"], pre, post)
ci.summary()

When i wanted to show the summary, plot, and inferences of Causal Impact, it got an error:

~\AppData\Roaming\Python\Python38\site-packages\causalimpact\analysis.py in summary(self, output, width, path)
    727         confidence = "{}%".format(int((1 - alpha) * 100))
    728         post_period = self.params["post_period"]
--> 729         post_inf = self.inferences.loc[post_period[0] : post_period[1], :]
    730         post_point_resp = post_inf.loc[:, "response"]
    731         post_point_pred = post_inf.loc[:, "point_pred"]

AttributeError: 'NoneType' object has no attribute 'loc'

Please help me, thank you.

Upvotes: 6

Views: 1792

Answers (1)

aaron
aaron

Reputation: 43073

Call ci.run() before ci.summary().

ci = CausalImpact(df_ci["INTERACTIONS IG"], pre, post)
ci.run()  # Add this
ci.summary()

Upvotes: 7

Related Questions