* 차분(Differencing): 현 시점 데이터에서 d시점 이전 데이터를 뺀 것 - 시계열 데이터의 추세를 제거하기 위해 데이터 간의 차이를 계산하는 과정 - 시계열 데이터가 안정적인 상태에 도달할 때까지 적용 차분 결과 시각화, 좌측에 특정한 트렌드를 가지고 있는 곡선이 차분된 모습
*hyperparameter: P, Q, D
1. P - 자기회귀(AR)부분의 차수 - 시계열 값이 과거 P시점 만큼 앞선 시점까지의 값에 의존하는 AR 모형의 차수 - ex. p=3, warm tomorrow if it has been warm the past 3 days 2. D - 1차 차분이 포함된 정도 - # of non-seasonal difference - ex. d=3, same temperature tomorrow if the difference in temperature in the last 3 days has been very small. - d를 구현하는 함수 diff(data, differenes=n): 차분을 통해 정상성을 만족시키는 것이 목적 3. Q - 이동 평균(MA) 부분의 차수 - 시계열 값이 과거 Q시점만큼 앞선 시점까지의 오차에 의존하는 MA 모형의 차수 - # of errors
yt′=c+ϕ1yt−1′+⋯+ϕpyt−p′+θ1ϵt−1+⋯+θqϵt−q+ϵt
ARIMA(1,0,0) = AR(1), ARIMA(0,0,1) = MR(1)
Auto Aarima: arima(data, order=c(p,d,q))에서 arima모델의 적절한 p,d,q를 추천해주는 함수
tsa (time series analysis)
From statsmodels. tsa import ArmaProcess (ar,ma)
pmdarima
통계검정을 사용해 정상성을 달성하기 위해 차분으로 조정하는 방식을 진행할 경우, 적용해야 할 차분의 차수를 알아낼 수 있는 방법
pmdarima의 ndiffs, nsdiffs함수를 사용
test 방식에는 adf, kpss, pp[필립-페론 검정] 가 있음
pip install pmdarima
from pmdarima.arima import ndiffs, nsdiffs
print(f"Suggested # of differences (ADF): {ndiffs(df.price, test='adf')}")
print(f"Suggested # of differences (KPSS): {ndiffs(df.price, test='kpss')}")
print(f"Suggested # of differences (PP): {ndiffs(df.price, test='pp')}")
stationarity(정상성/안정성), seasonality, adf/kpss stationarity test 이어서