取差分
在這個練習中,你要為某城市的人口時間序列做建模前的準備。如果你能預測城市的人口成長率,就能規劃並建設未來所需的基礎設施,讓公共支出更具前瞻性。這裡的時間序列是虛構的,但非常適合用來練習。
你會先用肉眼檢視平穩性,再使用增強型 Dicky-Fuller 檢定(Augmented Dicky-Fuller test),並透過取差分讓資料集變為平穩。
時間序列的 DataFrame 已為你載入為 city,而 adfuller() 函式也已匯入。
本練習屬於課程
Python 中的 ARIMA 模型
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Run the ADF test on the time series
result = ____(____)
# Plot the time series
fig, ax = plt.subplots()
city.plot(ax=ax)
plt.show()
# Print the test statistic and the p-value
print('ADF Statistic:', ____)
print('p-value:', ____)