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...