模型診斷

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 模型

相關圖(Correlogram)

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 模型

一起來練習吧!

Python 中的 ARIMA 模型

Preparing Video For Download...