Hello everyone, I am using a neuralnet package in R. I am using three 'x' variables to predict a 'y' variable. I am dealing with the time series data with 82 observations. I divided the data set into training and test sets. Using 'compute' function I tested the neuralnet fit model on test data. However, I want to forecast into future periods with no x data at hand. I am trying to use 'forecast' function. Is there any way to use forecast function for neuralnet package in R. I appreciate any help in this regard. Find the R code below:
## Creating Training (1:72) and Test Slices (73:82)
library(caret)
timeSlices <- createTimeSlices(1:nrow(data1),
initialWindow = 72, horizon = 10, fixedWindow = TRUE)
There are total 82 observations. I used createTimeSlices from caret package to create a training set (1:72) and test set (73:82). Now I use neuralnet packages to train the model as shown below:
library(neuralnet)
set.seed(101)
Model1 <- neuralnet(ppy ~ ppx1+ppx2+ppx3,data=mytraindata,
hidden=4, threshold=0.001, stepmax = 2e+05, rep = 1,
lifesign = "full", lifesign.step = 1000,
algorithm = "rprop+", err.fct = "sse",
act.fct = "logistic", linear.output = TRUE)
Now I predict the model on test set (73:82), with the following code,
Predmodel1 <- compute(Model1, Ntestdata)
Until this point everything is cool. However, I need to forecast the future y variables. I tried to use 'forecast' function to predict y values for the future 7 periods (i.e., periods 83:89) as follows
library(forecast)
predmodel2 <- forecast(Model1$net.result[[1]], 7)
I got the following error:
Error in ets(object, lambda = lambda, allow. multiplicative. trend = allow. multiplicative. trend, : y should be a univariate time series
Any thoughts how to forecast y into 7 periods (83:89) into future? To forecast the future 7 periods, let us assume that the Model1 is trained on observations 1:82. I greatly appreciate your feedback. Thank you.