Causal Impact Menggunakan Python – Part 4

Pada modul ini kita akan mulai implementasi Google Causal Impact.

Data Setup

Pertama kita remove data yang memiliki korelasi rendah, yaitu data stock ZAL.DE

df_final = df.drop(columns = ["ZAL.DE"])
df_final.head(1)

Mendefinisikan konstan untuk period training dan treatment. Untuk mempermudah kita dalam coding.

pre_period = [training_start, training_end]
post_period = [treatment_start, treatment_end]

Implementasi Google Causal Impact

impact = CausalImpact(data = df_final,
                      pre_period = pre_period,
                      post_period = post_period)
impact.plot()

Interpretasi Result

Dari graph diatas, dapat dilihat.

  • Graph pertama, Garis hitam adalah nilai aktual dari bitcoin. Garis orange putus-putus adalah prediksi berdasarkan data stock.
  • Graph kedua, ditunjukan delta dari garis hitam dan garis orange putus-putus dari graph pertama.
  • Graph ketiga, ditunjukan delta dari graph kedua kumulatif impact pada post period.

Dari graph diatas, dapat dilihat, pengumuman paypal memiliki efek pada pergerakan bitcoin. Impact paling kuat terjadi pada hari kedua, kemudian melandai pada hari ketiga.

Anda dapat melihat impact summary dan report dengan perintah impact.summary() dan impact.summary(‘report’) untuk melihat informasi summary dan informasi berupa narasi.

print(impact.summary())
Posterior Inference {Causal Impact}
                          Average            Cumulative
Actual                    12659.36           50637.45
Prediction (s.d.)         11038.02 (197.15)  44152.09 (788.62)
95% CI                    [10684.8, 11457.64][42739.21, 45830.55]

Absolute effect (s.d.)    1621.34 (197.15)   6485.36 (788.62)
95% CI                    [1201.73, 1974.56] [4806.91, 7898.24]

Relative effect (s.d.)    14.69% (1.79%)     14.69% (1.79%)
95% CI                    [10.89%, 17.89%]   [10.89%, 17.89%]

Posterior tail-area probability p: 0.0
Posterior prob. of a causal effect: 100.0%

For more details run the command: print(impact.summary('report'))
print(impact.summary('report'))
Analysis report {CausalImpact}


During the post-intervention period, the response variable had
an average value of approx. 12659.36. By contrast, in the absence of an
intervention, we would have expected an average response of 11038.02.
The 95% interval of this counterfactual prediction is [10684.8, 11457.64].
Subtracting this prediction from the observed response yields
an estimate of the causal effect the intervention had on the
response variable. This effect is 1621.34 with a 95% interval of
[1201.73, 1974.56]. For a discussion of the significance of this effect,
see below.


Summing up the individual data points during the post-intervention
period (which can only sometimes be meaningfully interpreted), the
response variable had an overall value of 50637.45.
By contrast, had the intervention not taken place, we would have expected
a sum of 44152.09. The 95% interval of this prediction is [42739.21, 45830.55].


The above results are given in terms of absolute numbers. In relative
terms, the response variable showed an increase of +14.69%. The 95%
interval of this percentage is [10.89%, 17.89%].


This means that the positive effect observed during the intervention
period is statistically significant and unlikely to be due to random
fluctuations. It should be noted, however, that the question of whether
this increase also bears substantive significance can only be answered
by comparing the absolute effect (1621.34) to the original goal
of the underlying intervention.


The probability of obtaining this effect by chance is very small
(Bayesian one-sided tail-area probability p = 0.0).
This means the causal effect can be considered statistically
significant.

Anda dapat gunakan file Google Colab untuk tutorial di Google Causal Impact.ipynb.

Sharing is caring: