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

77 Views Asked by At

I'm trying to do some forecast using the neural networks. I'm using the library neuralnet in R for the forecast. But when I submit the command predict, this error occurs

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

This is what my dataset looks like:

-df
Date        Price
30/01/2016  100
27/02/2016  109
10/03/2016  104
11/03/2016  91
10/04/2017  94
19/08/2017  114
23/11/2017  96
30/01/2018  102
11/05/2018  106
03/02/2019  101
11/03/2019  91
19/04/2019  104
22/08/2019  100
30/10/2020  88
30/11/2020  88
15/02/2021  87
30/06/2021  99

(of course this is a sample)

and this is my code:

df <- read_excel("C:/Users/df.xlsx")

df$Date <- as.Date(df$Date)

# packages
library(forecast)
library(neuralnet)
library(caret)

# 
set.seed(123)

# trainset
prop_training <- 0.7

# 
num_training <- round(nrow(df) * prop_training)

# random samples
training_indices <- sample(seq_len(nrow(df)), size = num_training, replace = FALSE)

# 
train_data <- df[training_indices, ]

# 
test_data <- df[-training_indices, ]


# model
model <- neuralnet(
  Price ~ Date,  
  data = train_data,
  hidden = c(5, 5),  
  linear.output = TRUE  
)

# prediction
predictions <- predict(model, newdata = test_data)

How can I resolve this?

0

There are 0 best solutions below