選擇合適的模型

Python 中的時間序列分析

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

辨識 AR 模型的階數

  • AR(p) 模型的階數通常未知
  • 判定階數的兩種方法
    • 偏自相關函數
    • 資訊準則
Python 中的時間序列分析

偏自相關函數(PACF)

Python 中的時間序列分析

在 Python 繪製 PACF

  • 與 ACF 類似,但用 plot_pacf 取代 plt_acf
  • 匯入模組
    from statsmodels.graphics.tsaplots import plot_pacf
    
  • 繪製 PACF
    plot_pacf(x, lags= 20, alpha=0.05)
    
Python 中的時間序列分析

不同 AR 模型的 PACF 比較

  • AR(1)

  • AR(3)

  • AR(2)

  • 白噪音

Python 中的時間序列分析

資訊準則

  • 資訊準則:將參數數量納入配適優度的調整
  • 兩個常用的調整後配適優度指標
    • AIC(Akaike Information Criterion)
    • BIC(Bayesian Information Criterion)
Python 中的時間序列分析

資訊準則

  • 估計輸出
Python 中的時間序列分析

從 statsmodels 取得資訊準則

  • 你先前已學會如何擬合 AR 模型
    from statsmodels.tsa.arima_model import ARIMA
    mod = ARIMA(simulated_data, order=(1,0))
    result = mod.fit()
    
  • 取得完整輸出
    result.summary()
    
  • 或只看參數
    result.params
    
  • 取得 AIC 與 BIC
    result.aic
    result.bic
    
Python 中的時間序列分析

資訊準則

  • 將模擬的 AR(3) 分別擬合為不同的 AR(p) 模型
  • 選擇 BIC 最小的 p 值
Python 中的時間序列分析

一起來練習吧!

Python 中的時間序列分析

Preparing Video For Download...