I'm using tfcausalimpact on Python to do some structural time series modeling. Results change from run to run, which I'd like to be able to avoid or control through some initial random state. Is there a way to obtain consistent results from run to run?
import numpy as np
import pandas as pd
from statsmodels.tsa.arima_process import ArmaProcess
from causalimpact import CausalImpact
np.random.seed(12345)
ar = np.r_[1, 0.9]
ma = np.array([1])
arma_process = ArmaProcess(ar, ma)
X = 100 + arma_process.generate_sample(nsample=100)
y = 1.2 * X + np.random.normal(size=100)
y[70:] += 5
data = pd.DataFrame({'y': y, 'X': X}, columns=['y', 'X'])
pre_period = [0, 69]
post_period = [70, 99]
ci = CausalImpact(data, pre_period, post_period)
print(ci.summary())
print(ci.summary(output='report'))
ci.plot()
#Run 1
Posterior Inference {Causal Impact}
Average Cumulative
Actual 125.23 3756.86
Prediction (s.d.) 120.41 (0.34) 3612.35 (10.34)
95% CI [119.73, 121.08] [3591.82, 3632.35]
Absolute effect (s.d.) 4.82 (0.34) 144.52 (10.34)
95% CI [4.15, 5.5] [124.51, 165.04]
Relative effect (s.d.) 4.0% (0.29%) 4.0% (0.29%)
95% CI [3.45%, 4.57%] [3.45%, 4.57%]
#Run 2
Posterior Inference {Causal Impact}
Average Cumulative
Actual 125.23 3756.86
Prediction (s.d.) 120.32 (0.33) 3609.48 (9.76)
95% CI [119.68, 120.95] [3590.28, 3628.53]
Absolute effect (s.d.) 4.91 (0.33) 147.39 (9.76)
95% CI [4.28, 5.55] [128.33, 166.58]
Relative effect (s.d.) 4.08% (0.27%) 4.08% (0.27%)
95% CI [3.56%, 4.62%] [3.56%, 4.62%]
Aucun commentaire:
Enregistrer un commentaire