상세 컨텐츠

본문 제목

R로 Forecasting하기

SCM and IT Knowledge&Usage

by Ultimatom 2023. 3. 1. 16:31

본문

728x90
반응형

1. 시계열 데이터 만들기

ts()

 

2. 시계열 데이터(Training data)를 가지고 Forecating하기

y = data, h=예측횟수

 

meanf(y, h)

예시:

b <- meanf(a10, h=10, level=95)
autoplot(b)

 

rwf(y, h)

예시:

d <- rwf(a10, h=10, level=95)
autoplot(d)

 

rwf(y, h, drift=TRUE)

예시:

e <- rwf(a10, h=10, level=95, drift =TRUE)
autoplot(e)

 

naive(y, h)

예시:

a <- naive(a10, h=10, level=95)
autoplot(a)

 

snaive(y, h)

예시:

c <- snaive(a10, h=10, level=95)
autoplot(c)

rwf() returns forecasts and prediction intervals for a random walk with drift model applied to y. This is equivalent to an ARIMA(0,1,0) model with an optional drift coefficient. naive() is simply a wrapper to rwf() for simplicity. snaive() returns forecasts and prediction intervals from an ARIMA(0,0,0)(0,1,0)m model where m is the seasonal period.

 

 

 

3. 더 적합한 Forecasting 모델 찾기(Forecasted data와 Test data 비교)

 

accuracy(forecasted data, test data)

 

 

Forecast 모델의 정확도를 판단할 때, RMSE를 많이 사용하는데, RMSE값이 적은 모델이 더 좋은 모델이다.

 

 

 

 

Time Series Cross Validation

tsCV(y, forecast method, h)

Trainig data와 Forecasted data와의 차이를 구한다.

 

e <- tsCV(dj, rwf, drift=TRUE, h=1)

sqrt(mean(e^2, na.rm=TRUE))

이 계산을 수행하고 나온 숫자가 적은 모델일 수록 좋은 모델이다.

 

728x90

관련글 더보기

댓글 영역