AIC와 BIC

Python으로 배우는 ARIMA 모델

James Fulton

Climate informatics researcher

AIC - 아카이케 정보 기준

  • AIC가 낮을수록 더 나은 모델
  • AIC는 낮은 차수의 단순한 모델을 선호함
Python으로 배우는 ARIMA 모델

BIC - 베이지안 정보 기준

  • AIC와 매우 유사
  • BIC가 낮을수록 더 나은 모델
  • BIC는 낮은 차수의 단순한 모델을 선호함
Python으로 배우는 ARIMA 모델

AIC vs BIC

  • BIC는 AIC보다 단순한 모델을 더 선호함
  • AIC는 예측 성능이 좋은 모델 선택에 유리
  • BIC는 설명력이 좋은 모델 선택에 유리
Python으로 배우는 ARIMA 모델

statsmodels의 AIC와 BIC

# 모델 생성
model = ARIMA(df, order=(1,0,1))

# 모델 적합 results = model.fit()
# 요약 출력 print(results.summary())
                            Statespace Model Results                           
==============================================================================
Dep. Variable:                      y   No. Observations:                 1000
Model:               SARIMAX(2, 0, 0)   Log Likelihood               -1399.704
Date:                Fri, 10 May 2019   AIC                           2805.407
Time:                        01:06:11   BIC                           2820.131
Sample:                    01-01-2013   HQIC                          2811.003
                         - 09-27-2015                                         
Covariance Type:                  opg
Python으로 배우는 ARIMA 모델

statsmodels의 AIC와 BIC

# 모델 생성
model = ARIMA(df, order=(1,0,1))

# 모델 적합 results = model.fit()
# AIC와 BIC 출력 print('AIC:', results.aic) print('BIC:', results.bic)
AIC: 2806.36 
BIC: 2821.09
Python으로 배우는 ARIMA 모델

AIC와 BIC 탐색

# AR 차수 반복
for p in range(3):
    # MA 차수 반복
    for q in range(3):

# 모델 적합 model = ARIMA(df, order=(p,0,q)) results = model.fit()
# 모델 차수와 AIC/BIC 출력 print(p, q, results.aic, results.bic)
0 0 2900.13 2905.04
0 1 2828.70 2838.52
0 2 2806.69 2821.42
1 0 2810.25 2820.06
1 1 2806.37 2821.09
1 2 2807.52 2827.15
...
Python으로 배우는 ARIMA 모델

AIC와 BIC 탐색

order_aic_bic =[]
# AR 차수 반복
for p in range(3):
    # MA 차수 반복
    for q in range(3):

# 모델 적합 model = ARIMA(df, order=(p,0,q)) results = model.fit()
# 차수와 점수를 리스트에 추가 order_aic_bic.append((p, q, results.aic, results.bic))
# 모델 차수와 AIC/BIC로 DataFrame 생성
order_df = pd.DataFrame(order_aic_bic, columns=['p','q', 'aic', 'bic'])
Python으로 배우는 ARIMA 모델

AIC와 BIC 탐색

# AIC로 정렬
print(order_df.sort_values('aic'))
   p  q      aic      bic
7  2  1  2804.54  2824.17
6  2  0  2805.41  2820.13
4  1  1  2806.37  2821.09
2  0  2  2806.69  2821.42
...
# BIC로 정렬
print(order_df.sort_values('bic'))
   p  q      aic      bic
3  1  0  2810.25  2820.06
6  2  0  2805.41  2820.13
4  1  1  2806.37  2821.09
2  0  2  2806.69  2821.42
...
Python으로 배우는 ARIMA 모델

비정상(Non-stationary) 차수

# 모델 적합
model = ARIMA(df, order=(2,0,1))
results = model.fit()
ValueError: Non-stationary starting autoregressive parameters
found with `enforce_stationarity` set to True.
Python으로 배우는 ARIMA 모델

특정 차수가 안 될 때

# AR 차수 반복
for p in range(3):
    # MA 차수 반복
    for q in range(3):

# 모델 적합 model = ARIMA(df, order=(p,0,q)) results = model.fit() # 모델 차수와 AIC/BIC 출력 print(p, q, results.aic, results.bic)
Python으로 배우는 ARIMA 모델

특정 차수가 안 될 때

# AR 차수 반복
for p in range(3):
    # MA 차수 반복
    for q in range(3):

try: # 모델 적합 model = ARIMA(df, order=(p,0,q)) results = model.fit() # 모델 차수와 AIC/BIC 출력 print(p, q, results.aic, results.bic)
except: # 실패 시 AIC/BIC를 None으로 출력 print(p, q, None, None)
Python으로 배우는 ARIMA 모델

Ayo berlatih!

Python으로 배우는 ARIMA 모델

Preparing Video For Download...