0

I am attempting to train a neural network but got this message. Can you tell me why? Is it because it should be numeric? I have a question mark if there is missing data. Should I change this?

> dataset <- read.csv("~/DATA630/ucidatasethouse-votes-84.data.csv")
> trainset <- dataset[1:305, ]
> testset <- dataset[306:435, ]
> polpartynet <- neuralnet(Party ~ HndcpInfants + WaterProject + AdoptBudget + DocFeeFreeze + ElSalvadorAid + ReligiousGroupsSchools + AntiSatellTestBan + AidNicaraguaContras + MXMissile + Immigration + SynCorpCutback + EducationSpending + SuperfundRighttoSue + Crime + DutyFreeExports + ExportAdminSouthAfrica, trainset, hidden = 4, lifesign = "minimal", linear.output = FALSE, threshold = 0.1)
hidden: 4    thresh: 0.1    rep: 1/1    steps: 
Error in neurons[[i]] %*% weights[[i]] : 
  requires numeric/complex matrix/vector arguments

This is what some of my data looks like....Party is the first column(numeric) and ExportAdminSouthAfrica is the last column.

Party   HndcpInfants    WaterProject    AdoptBudget DocFeeFreeze    ElSalvadorAid   ReligiousGroupsSchools  AntiSatellTestBan   AidNicaraguaContras MXMissile   Immigration SynCorpCutback  EducationSpending   SuperfundRighttoSue Crime   DutyFreeExports ExportAdminSouthAfrica
1   n   y   n   y   y   y   n   n   n   y   ?   y   y   y   n   y
1   n   y   n   y   y   y   n   n   n   n   n   y   y   y   n   ?
2   ?   y   y   ?   y   y   n   n   n   n   y   n   y   y   n   n
2   n   y   y   n   ?   y   n   n   n   n   y   n   y   n   n   y
2   y   y   y   n   y   y   n   n   n   n   y   ?   y   y   y   y
2   n   y   y   n   y   y   n   n   n   n   n   n   y   y   y   y
2   n   y   n   y   y   y   n   n   n   n   n   n   ?   y   y   y
1   n   y   n   y   y   y   n   n   n   n   n   n   y   y   ?   y
1   n   y   n   y   y   y   n   n   n   n   n   y   y   y   n   y
IainDunning
  • 11,546
  • 28
  • 43
  • What is the class of your variables? I guess you have likely already thought of this, but it may also be worth considering if a different model isn't more appropriate. – verybadatthis Apr 21 '15 at 20:06
  • I 'm still learning terms. Class? All my variables are Factors. Does this matter? Should I change the question mark? > d <- read.csv("~/DATA630/ucidatasethouse-votes-84.data.csv") > str(d) 'data.frame': 435 obs. of 17 variables: $ Party : Factor w/ 2 levels "democrat","republican": 2 2 1 1 1 1 1 2 2 1 ... $ HndcpInfants : Factor w/ 3 levels "?","n","y": 2 2 1 2 3 2 2 2 2 3 $ WaterProject : Factor w/ 3 levels "?","n","y": 3 3 3 3 3 3 3 3 3 3 – BJ Williams Apr 21 '15 at 20:58
  • Neural network naturally works with numeric variables. Of course, you can one-hot-encode factor variables and proceed. But since _all_ your variables are factors, _why_ do you want neural network in the first place? – lanenok Apr 21 '15 at 21:12
  • The way to do this is turning them factors binary dummy variables, where each level of the factor is a separate column. The best way to do this is with model.matrix, as detailed in [this answer](http://stackoverflow.com/questions/3384506/create-new-dummy-variable-columns-from-categorical-variable). Alternatively, you can use the dummyVars function from the package caret, [detailed here](http://stackoverflow.com/questions/12758075/how-to-create-dummy-variables). – verybadatthis Apr 21 '15 at 21:46
  • It's a class assignment. I will switch the n, y, ? to 1, 2, 3 and the party to -1 and 0. How does that sound? Thanks for your comments. – BJ Williams Apr 21 '15 at 21:46
  • This is the latest message that I'm receiving. Please help. > polparty <- neuralnet(Party ~ HandInfants + WaterProject + AdoptBudget + DocFeeFreeze + ElSalvadorAid + ReligiousGroupsSchools + AntiSatellTestBan + AidNicaraguaContas + MXMissile + Immigration + SynCorpCutback + EducationSpending + SuperfundRighttoSue + Crime + DutyFreeExports + ExportAdminSouthAfrica, trainset, hidden = 4, lifesign = "minimal", linear.output = FALSE, threshold = 0.1) Error in eval(expr, envir, enclos) : object 'HandInfants' not found – BJ Williams Apr 22 '15 at 03:42

0 Answers0