Skip to main content

단위근 검정

Augmented Dickey-Fuller Test

from statsmodels.tsa.stattools import adfuller
adfuller(beer.production)

구글 주가 데이터

df = pd.read_excel('GOOG.xlsx')
y = df.Price
y.plot()

ACF가 완만하게 떨어지는 형태

plot_acf(y)

KPSS 검정

from statsmodels.tsa.stattools import kpss
kpss(y)

차분

1차 차분

yd = y.diff().dropna()
plot_acf(yd)

2차 차분: 차분한 값을 다시 차분

yd2 = yd.diff().dropna()
plot_acf(yd2)

2차 차분한 결과의 KPSS 검정

kpss(yd2)

미국 전기생산량 데이터

el = pd.read_excel('usmelec.xlsx')
y = el.elec
y.plot()
plot_acf(y)

계절성 차분 seasonal differencing

ys = y.diff(12).dropna()
ys.plot()
plot_acf(ys)

1차 차분과 계절성 차분

ysd = y.diff(12).diff().dropna()
ysd.plot()
plot_acf(ysd)