2

I have a data frame named IED2. I tried to use neuralnet package in R to develop a forecasting model on one column Prop.of.Proper.Cleared of this IED2. Since the data is in terms of time-series, I used createTimeSlices method and expanding -window rolling forecasting to create the training and testing datasets. But then when running the for loop below, I kept getting the error message that I could not fi, despite checking to make sure the data type of each columns is integer.

Error in cbind(1, pred) %*% weights[[num_hidden_layers + 1]] :   
requires numeric/complex matrix/vector arguments

My Code

 timeSlices <- createTimeSlices(1:nrow(IED2), 
                                initialWindow = 90, horizon = 62, fixedWindow = FALSE)

trainSlices <- timeSlices[[1]]
testSlices <- timeSlices[[2]]

test = NULL
net.sqrt = NULL
err = NULL
col_list <- paste(c(colnames(IED2[,5:7])),collapse="+")
col_list <- paste(c("Prop.of.Proper.Clear~",col_list),collapse="")
f <- formula(col_list)

for(i in 1:2000){
  set.seed(1)
  net.sqrt[i] <- neuralnet(f, data = IED2[trainSlices[[i]],] , algorithm = "rprop+", hidden=2, threshold=0.01, 
                        learningrate = 0.0001, linear.output = TRUE, err.fct="sse")
  test[i] <- compute(net.sqrt[i], IED2[testSlices[[i]],5:7])
  err[i] <- ((test[i]$net.result - IED2[testSlices[[i]],13])^2)/nrow(IED2[testSlices[[i]],])
}

Can anyone please help me with this issue?

Sample Dataset with dput

structure(list(DoW = c(2L, 3L, 4L, 5L, 7L, 1L), Mnth = c(1L,  1L, 1L, 1L, 1L, 1L), Hour = c(0L, 0L, 0L,
 0L, 0L, 0L), Prop.of.Proper.Clear = c(0.333333333, 
 0.2, 0.333333333, 0.125, 0, 0)), row.names = c(2L, 3L, 4L, 5L,  7L, 8L), class = "data.frame")
M--
  • 25,431
  • 8
  • 61
  • 93
user177196
  • 738
  • 1
  • 8
  • 16
  • 1
    Take a look at this for some pointers: https://stackoverflow.com/questions/22906804/matrix-expression-causes-error-requires-numeric-complex-matrix-vector-arguments – NelsonGon May 05 '19 at 12:49
  • I took a look at the link you showed, but it's not relevant to `neuralnet` package. Still left puzzled. – user177196 May 05 '19 at 23:29

0 Answers0