0

hi i am trying to use neuralnet function in R so i can predict an integer outcome (meaning) using the rest of the variables. here is the code that i have used:

library("neuralnet")

I am going to put 2/3 from the data for neural network learning and the rest for test

ind<-sample(1:nrow(Data),6463,replace=FALSE)

Train<-Data[ind,]

Test<-Data[-ind,]

m <- model.matrix(
  ~meaning + 
    firstLevelAFFIRM + firstLevelDAT.PRSN + firstLevelMODE + 
    firstLevelO.DEF + firstLevelO.INDIV + firstLevelS.AGE.INDIV + 
    secondLevelV.BIN + secondLevelWord1 + secondLevelWord2 + 
    secondLevelWord3 + secondLevelWord4 + thirdLevelP.TYPE,
  data = Train[,-1])  #(the first column is ID , i am not going to use it)

PredictorVariables <- paste("m[," , 3:ncol(m),"]" ,sep="")

Formula <- formula(paste("meaning ~ ", paste(PredictorVariables, collapse=" + ")))

net <- neuralnet(Formula,data=m, hidden=3, threshold=0.05)

m.test < -model.matrix(
  ~meaning + 
    firstLevelAFFIRM + firstLevelDAT.PRSN + firstLevelMODE + 
    firstLevelO.DEF + firstLevelO.INDIV + firstLevelS.AGE.INDIV + 
    secondLevelV.BIN + secondLevelWord1 + secondLevelWord2 + 
    secondLevelWord3 + secondLevelWord4 + thirdLevelP.TYPE,
  data = Test[,-1])

net.results <- compute(net, m.test[,-c(1,2)]) #(first column is ID and the second one is the outcome that i am trying to predict)

output<-cbind(round(net.results$net.result),Test$meaning)

mean(round(net.results$net.result)!=Test$meaning)

the misclassification that i got was around 0.01 which is great, but my question is why the outcome that i got (net.results$net.result) is not an integer?

arvi1000
  • 9,393
  • 2
  • 42
  • 52
Basel.D
  • 349
  • 1
  • 18

1 Answers1

1

I assume that your output is linear. Try setting linear.output = FALSE.

net <- neuralnet(Formula, data = m, hidden = 3, threshold = 0.05, linear.output = FALSE)

Agaz Wani
  • 5,514
  • 8
  • 42
  • 62
PvG
  • 86
  • 10
  • no it did not help , now i am getting different answers still not integers and all of them are less than 1 (0.99...) – Basel.D Feb 01 '16 at 15:45
  • I think your formula is producing probabilities. I know that in the nnet packages (and probably the neuralnet as well) it's easier to calculate your results with the `predict` function. In this function you can set the prediction outcome to class instead of probability. Furthermore you target variable should be binary. I don't know if it is multinomial but if that is the case you should use `class.ind()` . For more information on that question check this topic: http://stackoverflow.com/questions/20813039/multinomial-classification-using-neuralnet-package – PvG Feb 01 '16 at 15:58