始める無料で始める

気温は(ドリフト付きの)ランダムウォークですか?

ARMA モデルは気候変動の予測としては単純な手法ですが、この講座で扱う多くのトピックを示すよい例になります。

DataFrame temp_NY には、セントラルパーク(NY)の 1870〜2016 年の年間平均気温が入っています(データは NOAA から こちら で取得しました)。このデータをプロットし、ドリフト付きランダムウォークに従うかどうかを検定してください。

この演習はコースの一部です

Pythonで学ぶ時系列解析

コースを見る

演習の手順

  • 年のインデックスを pd.to_datetime() で datetime オブジェクトに変換し、年次データなので引数 format='%Y' を渡します。
  • .plot() を使ってデータをプロットします。
  • adfuller 関数を使って拡張 Dickey-Fuller 検定の p 値を計算します。
  • ADF 検定の結果を result に保存し、result[1] の p 値を出力します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Import the adfuller function from the statsmodels module
from statsmodels.tsa.stattools import adfuller

# Convert the index to a datetime object
temp_NY.index = pd.to_datetime(___.___, format=___)

# Plot average temperatures
temp_NY.___
plt.show()

# Compute and print ADF p-value
result = ___(temp_NY['TAVG'])
print("The p-value for the ADF test is ", result[1])
コードを編集して実行