ウォームアップ:自己相関を見てみましょう
気温系列 temp_NY はトレンド付きランダムウォークなので、一次差分をとって定常化します。次に標本 ACF と PACF を計算しましょう。これによりモデル次数の目安が得られます。
この演習はコースの一部です
Pythonで学ぶ時系列解析
演習の手順
- 標本 ACF と PACF をプロットするためのモジュールをインポートします
- pandas の
.diff()メソッドを使って DataFrametemp_NYの一次差分をとります - ACF と PACF を描画するために 2 つのサブプロットを作成します
- 差分系列の標本 ACF をプロットします
- 差分系列の標本 PACF をプロットします
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import the modules for plotting the sample ACF and PACF
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
# Take first difference of the temperature Series
chg_temp = ___.___
chg_temp = chg_temp.dropna()
# Plot the ACF and PACF on the same page
fig, axes = plt.subplots(2,1)
# Plot the ACF
plot_acf(___, lags=20, ax=axes[0])
# Plot the PACF
plot_pacf(___, lags=20, ax=axes[1])
plt.show()