季節性時間序列

Python 中的 ARIMA 模型

James Fulton

Climate informatics researcher

季節性資料

  • 具有可預測、重覆的型態
  • 會在一段時間後重現
Python 中的 ARIMA 模型

季節性分解

Python 中的 ARIMA 模型

季節性分解

時間序列 = 趨勢 + 季節性 + 殘差

Python 中的 ARIMA 模型

使用 statsmodels 進行季節性分解

# Import 
from statsmodels.tsa.seasonal import seasonal_decompose
# Decompose data
decomp_results = seasonal_decompose(df['IPG3113N'], period=12)
type(decomp_results)
statsmodels.tsa.seasonal.DecomposeResult
Python 中的 ARIMA 模型

使用 statsmodels 進行季節性分解

# Plot decomposed data
decomp_results.plot()
plt.show()

Python 中的 ARIMA 模型

用 ACF 尋找季節週期

Python 中的 ARIMA 模型

用 ACF 辨識季節性資料

Python 中的 ARIMA 模型

移除趨勢(Detrending)時間序列

# Subtract long rolling average over N steps
df = df - df.rolling(N).mean()

# Drop NaN values df = df.dropna()

Python 中的 ARIMA 模型

用 ACF 辨識季節性資料

# Create figure
fig, ax = plt.subplots(1,1, figsize=(8,4))

# Plot ACF
plot_acf(df.dropna(), ax=ax, lags=25, zero=False)
plt.show()

Python 中的 ARIMA 模型

ARIMA 模型與季節性資料

Python 中的 ARIMA 模型

一起來練習吧!

Python 中的 ARIMA 模型

Preparing Video For Download...