モデル診断

Pythonで学ぶARIMAモデル

James Fulton

Climate informatics researcher

モデル診断の概要

  • 最終モデルはどの程度よいか?
Pythonで学ぶARIMAモデル

残差

Pythonで学ぶARIMAモデル

残差

# Fit model
model = ARIMA(df, order=(p,d,q))
results = model.fit()

# Assign residuals to variable residuals = results.resid
2013-01-23    1.013129
2013-01-24    0.114055
2013-01-25    0.430698
2013-01-26   -1.247046
2013-01-27   -0.499565
       ...         ...
Pythonで学ぶARIMAモデル

平均絶対誤差

予測は実測からどれだけ離れているか?

mae = np.mean(np.abs(residuals))
Pythonで学ぶARIMAモデル

診断プロット

モデルが適合していれば,残差は白色ガウス雑音になります。

# Create the 4 diagostics plots
results.plot_diagnostics()
plt.show()

Pythonで学ぶARIMAモデル

残差プロット

Pythonで学ぶARIMAモデル

残差プロット

Pythonで学ぶARIMAモデル

ヒストグラムと推定密度

Pythonで学ぶARIMAモデル

正規Q-Q

Pythonで学ぶARIMAモデル

相関図(コレログラム)

Pythonで学ぶARIMAモデル

要約統計量

print(results.summary())
...
===================================================================================
Ljung-Box (Q):                       32.10   Jarque-Bera (JB):                 0.02
Prob(Q):                              0.81   Prob(JB):                         0.99
Heteroskedasticity (H):               1.28   Skew:                            -0.02
Prob(H) (two-sided):                  0.21   Kurtosis:                         2.98
===================================================================================
  • Prob(Q) - 残差が無相関であるという帰無仮説のp値
  • Prob(JB) - 残差が正規であるという帰無仮説のp値
Pythonで学ぶARIMAモデル

Let's practice!

Pythonで学ぶARIMAモデル

Preparing Video For Download...