1

I am pretty new to the r package neuralnet. So the problem I encounter could be 'easy' to solve, but still i haven't succeeded yet.

I have a dataframe that looks like this (only the first 5 rows are shown):

  var1 var2 var40 var44 var46 var70 var202 var239 var343 var345 var1103
1    5    4     3     5     1     5      4      4      4     NA       3
2    4    2     2     4     4     2      4      2      4     NA       1
3    4    3     4     4     2     4      3      5      3     NA       4
4    4    4     4     4     3     3      5      5      4     NA       4
5    5    1     5     5     5     5      5      1      5     NA       1

var345 doesn't have NA's on each row.

This is the structure information:

'data.frame':   22536 obs. of  11 variables:
 $ var1   : num  5 4 4 4 5 4 3 4 4 5 ...
 $ var2   : num  4 2 3 4 1 1 4 4 4 5 ...
 $ var40  : num  3 2 4 4 5 1 4 3 5 4 ...
 $ var44  : num  5 4 4 4 5 1 3 3 5 4 ...
 $ var46  : num  1 4 2 3 5 1 3 2 1 2 ...
 $ var70  : num  5 2 4 3 5 1 4 4 4 5 ...
 $ var202 : num  4 4 3 5 5 1 4 4 5 4 ...
 $ var239 : num  4 2 5 5 1 1 4 3 5 4 ...
 $ var343 : num  4 4 3 4 5 1 3 4 2 5 ...
 $ var345 : num  NA NA NA NA NA NA NA NA NA NA ...
 $ var1103: num  3 1 4 4 1 1 2 NA 4 4 ...

When I split this data frame into a trainingset (75% of the data) and a test set (25% of the data), I try to train a neural net on predicting "var1103" by using the rest of the variabeles as predictors:

nn <- neuralnet(var1103~var1+var345+var70+var46+var343+var40+var44+var202+var239+var2,train2, hidden=10, threshold=0.01)

I keap on getting this error:

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

Does anyone have a clue about what's going wrong here and how to solve it? To me the data frame looks rather straight forward, but I could be wrong ofcourse. I have allready tried to convert the variables into factors. This had the same error as a result.

rdatasculptor
  • 8,112
  • 14
  • 56
  • 81
  • 2
    I would start with excluding `var345`. – zero323 Nov 05 '13 at 10:22
  • 1
    var345 has NA's but so do other variables as well. Can't neuralnet handle NA's? – rdatasculptor Nov 05 '13 at 10:31
  • Probably. I've never used `neuralnet` library myself but if you think how neural networks work handling `NA` could by tricky. – zero323 Nov 05 '13 at 10:42
  • Well, I've installed `neuralnet` and I couldn't reproduce error mentioned, but I get `Error in x - y : non-conformable arrays`. If I omit `var345` it works fine so it seems I was at least partially right about `NA`s. – zero323 Nov 05 '13 at 10:47
  • 1
    Most machine learning algorithms require that variables do not have any missing values. One simple way to deal with the problem of missing values is to immute them with the column mean. Once all the missing values are imputed you could pass the data frame to the neural net function. Hopefully this should fix it. Try searching for "Missing value imputation strategies" –  Nov 05 '13 at 10:55
  • It works! The cause of the problem was indeed the NA's. I am using the imputation package now to experiment with different kinds of imputation. – rdatasculptor Nov 05 '13 at 13:10
  • http://stackoverflow.com/questions/17457028/working-with-neuralnet-in-r-for-the-first-time-get-requires-numeric-complex-ma – Hitesh Goyal Jun 02 '15 at 09:52

0 Answers0