ARIMA 模型導論

Python 中的 ARIMA 模型

James Fulton

Climate informatics researcher

非定態時間序列複習

Python 中的 ARIMA 模型

非定態時間序列複習

Python 中的 ARIMA 模型

差分後時間序列的預測

Python 中的 ARIMA 模型

差分後重建原始時間序列

diff_forecast = results.get_forecast(steps=10).predicted_mean

from numpy import cumsum
mean_forecast = cumsum(diff_forecast)
Python 中的 ARIMA 模型

差分後重建原始時間序列

diff_forecast = results.get_forecast(steps=10).predicted_mean

from numpy import cumsum
mean_forecast = cumsum(diff_forecast) + df.iloc[-1,0]
Python 中的 ARIMA 模型

差分後重建原始時間序列

Python 中的 ARIMA 模型

ARIMA 模型

 

  • 先做差分
  • 擬合 ARMA 模型
  • 將預測做積分

能不能少做一點工?

可以!

ARIMA-自迴歸整合移動平均

Python 中的 ARIMA 模型

使用 ARIMA 模型

from statsmodels.tsa.arima.model import ARIMA

model = ARIMA(df, order=(p,d,q))
  • p-自迴歸落後期數
  • d-差分階數
  • q-移動平均落後期數

ARIMA$(p,0,q)$ = ARMA$(p,q)$

Python 中的 ARIMA 模型

使用 ARIMA 模型

# Create model
model = ARIMA(df, order=(2,1,1))

# Fit model model.fit()
# Make forecast mean_forecast = results.get_forecast(steps=10).predicted_mean
Python 中的 ARIMA 模型

使用 ARIMA 模型

# Make forecast
mean_forecast = results.get_forecast(steps=steps).predicted_mean

Python 中的 ARIMA 模型

選擇差分階數

adf = adfuller(df.iloc[:,0])
print('ADF Statistic:', adf[0])
print('p-value:', adf[1])
ADF Statistic: -2.674
p-value: 0.0784
adf = adfuller(df.diff().dropna().iloc[:,0])
print('ADF Statistic:', adf[0])
print('p-value:', adf[1])
ADF Statistic: -4.978
p-value: 2.44e-05
Python 中的 ARIMA 模型

選擇差分階數

model = ARIMA(df, order=(p,1,q))
Python 中的 ARIMA 模型

一起來練習吧!

Python 中的 ARIMA 模型

Preparing Video For Download...