Skip to content

test_forecast example

Rami Krispin edited this page Jul 26, 2018 · 2 revisions

Example of the test_forecast function usage

Loading required packages

library(TSstudio)

library(forecast)

Loading example dataset - US natural gas consumption

data(USgas)

ts_plot(USgas)

Setting the horizon of the testing partition

h = 24

Split the series into training and testing, leaving the last 24 hours of the series for testing

USgas_split <- ts_split(USgas, sample.out = h)

train <- USgas_split$train

test <- USgas_split$test

Train few forecasting models

md1 <- auto.arima(train) # ARIMA model

md2 <- ets(train) # ETS model

md3 <- nnetar(train, p = 12, P = 2) # Neural Network for time series

Testing the models using horizon of 24 months

fc1 <- forecast(md1, h = h)

fc2 <- forecast(md2, h = h)

fc3 <- forecast(md3, h = h)

Ploting the results with the test_forecast function

test_forecast(actual = USgas, forecast.obj = fc1, test = test)

test_forecast(actual = USgas, forecast.obj = fc2, test = test)

test_forecast(actual = USgas, forecast.obj = fc3, test = test)