SARIMA 模型

Python 中的 ARIMA 模型

James Fulton

Climate informatics researcher

SARIMA 模型

季節性 ARIMA = SARIMA

  • 非季節階數
    • p:自迴歸階數
    • d:差分階數
    • q:移動平均階數

SARIMA(p,d,q)(P,D,Q)$_S$

  • 季節性階數
    • P:季節自迴歸階數
    • D:季節差分階數
    • Q:季節移動平均階數
    • S:每循環的時間步數
Python 中的 ARIMA 模型

SARIMA 模型

ARIMA(2,0,1) 模型: $$y_t = a_1 y_{t-1} + a_2 y_{t-2} + m_1 \epsilon_{t-1} + \epsilon_t$$

SARIMA(0,0,0)(2,0,1)$_7$ 模型: $$y_t = a_7 y_{t-7} + a_{14} y_{t-14} + m_7 \epsilon_{t-7} + \epsilon_t$$

Python 中的 ARIMA 模型

擬合 SARIMA 模型

# Imports
statsmodels.tsa.statespace.sarimax import SARIMAX

# Instantiate model model = SARIMAX(df, order=(p,d,q), seasonal_order=(P,D,Q,S))
# Fit model results = model.fit()
Python 中的 ARIMA 模型

季節差分

減去前一季的時間序列值

$$\Delta y_t = y_t - y_{t-S}$$

# Take the seasonal difference
df_diff = df.diff(S)
Python 中的 ARIMA 模型

SARIMA 的差分處理

時間序列

Python 中的 ARIMA 模型

SARIMA 的差分處理

一階差分的時間序列

Python 中的 ARIMA 模型

SARIMA 的差分處理

一階差分與一階季節差分的時間序列

Python 中的 ARIMA 模型

尋找 p 與 q

Python 中的 ARIMA 模型

尋找 P 與 Q

Python 中的 ARIMA 模型

繪製季節性 ACF 與 PACF

# Create figure
fig, (ax1, ax2) = plt.subplots(2,1)

# Plot seasonal ACF
plot_acf(df_diff,  lags=[12,24,36,48,60,72], ax=ax1)

# Plot seasonal PACF
plot_pacf(df_diff, lags=[12,24,36,48,60,72], ax=ax2)

plt.show()
Python 中的 ARIMA 模型

一起來練習吧!

Python 中的 ARIMA 模型

Preparing Video For Download...