AR 모델 추정 및 예측

Python으로 배우는 시계열 분석

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

AR 모델 추정

  • 데이터(시뮬레이션)에서 파라미터 추정

    from statsmodels.tsa.arima_model import ARMA
    mod = ARMA(data, order=(1,0))
    result = mod.fit()
    
  • ARMA는 더 이상 사용되지 않으며 ARIMA로 대체됨

    from statsmodels.tsa.arima.model import ARIMA
    mod = ARIMA(data, order=(1,0,0))
    result = mod.fit()
    
  • ARMA: order=(p,q)

  • ARIMA: order=(p,d,q)
Python으로 배우는 시계열 분석

AR 모델 추정

  • 전체 출력 결과 (실제값 $\large \mu=0$, $\large \phi=0.9$)
    print(result.summary())
    

Python으로 배우는 시계열 분석

AR 모델 추정

  • $\large \mu$와 $\large \phi$의 추정값만 출력 (실제값 $\large \mu=0$, $\large \phi=0.9$)
    print(result.params)
    
array([-0.03605989,  0.90535667])
Python으로 배우는 시계열 분석

AR 모델로 예측하기

from statsmodels.graphics.tsaplots import plot_predict
fig, ax = plt.subplots()
data.plot(ax=ax)
plot_predict(result, start='2012-09-27', end='2012-10-06', alpha=0.05, ax=ax)
plt.show()
  • plot_predict() 함수의 인수
    • 첫 번째 인수: 적합된 모델
    • alpha=None 설정 시 신뢰 구간 미표시
    • ax=ax 설정 시 데이터와 예측을 동일 축에 표시

Python으로 배우는 시계열 분석

연습해 봅시다!

Python으로 배우는 시계열 분석

Preparing Video For Download...