1

I am playing around with Adult Dataset https://archive.ics.uci.edu/ml/datasets/adult and R. I am trying to use the neuralnet package to train a Neural Network with Back propagation. I have cleaned the data. Now I am trying to run this part :

n <- names(cleanTrain)
f <- as.formula(paste("income~", paste(n[!n %in% "income"], collapse = " + ")))
nn <- neuralnet(f, data=cleanTrain, hidden = 10, algorithm = "backprop", learningrate=0.35)

I get this ERROR:

Error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments

P.S:

  1. I load the train as cleanTrain
  2. n gets all the names of the dataset
  3. f returns income ~ age + workclass + education + education.num + marital.status + occupation + relationship + race +sex + capital.gain + capital.loss + hours.per.week + native.country

Which is the error?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Ioannis K
  • 95
  • 1
  • 9
  • Check your data types for each column? – Mako212 Jan 03 '18 at 17:14
  • What do you mean? It has to be only numerical values for example? – Ioannis K Jan 03 '18 at 17:16
  • Try with a simpler formula first like `income ~ age` and see if your model runs. Assuming it does, you can add variables one at a time until you find the one that causes the issue. If I had to guess, you might need to switch anything that's a `factor` to `character` but I haven't worked with this library, so that's just a guess. – Mako212 Jan 03 '18 at 17:19
  • Ok! Thank you for your Time ! :D – Ioannis K Jan 03 '18 at 17:21

1 Answers1

0

Hello first use a function to clean the Adult database, which you can find at Statistical Consulting Group, then convert all the variables into numeric, if the backpropagation algorithm does not work. You can see an example at neural net in R. Finally apply the algorithm with the following code.

source("http://scg.sdsu.edu/wp-content/uploads/2013/09/dataprep.r")
train = as.data.frame(sapply(data$train, as.numeric))
train$income = train$income-1

library(neuralnet)
n <- names(train)
f <- as.formula(paste("income~", paste(n[!n %in% "income"], collapse = " + ")))
nn <- neuralnet(f,data=train,hidden=10,err.fct="sse",linear.output=FALSE,algorithm="backprop",learningrate=0.35)
nn

I hope it helps you. regards

Rafael Díaz
  • 2,134
  • 2
  • 16
  • 32