1
$\begingroup$

I have explored this site for the answer but could not find what i was looking for. My problem is i have data containing many variables (22) that are continuos and categorical and my output has two levels 1(present) or 0 (absent). My questions are:

1) What type of library, for a neural network model, would be best for this type of data (nnet or neuralnet in r)

2) I have been told that this is a regression problem not a classification, however since my output only has two levels why is this regression and not classification?

$\endgroup$
1
$\begingroup$

Both packages neuralnet and nnet can be used for your task.

If you receive warnings on you are running regression but not classification, try to change the type for the response variable using function factor.

library(nnet)
library(mlbench)


set.seed(0)
d=mlbench.2dnormals(500)
plot(d)
d=data.frame(x1=d$x[,1],x2=d$x[,2],y=d$classes)

# nnet function from nnet package
fit1<-nnet(y~.,data=d,size=10)
fit1

# nnet from neuralnet package
library(neuralnet)
d$y=as.numeric(d$y)
fit2<-neuralnet(y~x1+x2,data=d,hidden=10)
fit2
$\endgroup$
5
  • $\begingroup$ Thank you, however when i convert my response variable into a factor in the neuralnet package i get an error message stating that i am using the wrong model for classification ? $\endgroup$ – Martin May 19 '17 at 17:08
  • $\begingroup$ @Martin hard for me to see what's happening with limited information here. But I will give you 2 examples on each package by revising answer. $\endgroup$ – Haitao Du May 19 '17 at 17:13
  • $\begingroup$ Thank you for the example. This works fine for me and i can do both types of models from each package with no problem. however, when i try to cross validate this, under the caret package, i get the error message, "wrong model for classification", even when i convert the response variable to a factor. This is where my confusion comes from and why i ask the question, "is this is a classification or a regression problem", as it seems running the 'neuralnet' package with a factor as the response variable does not work? $\endgroup$ – Martin May 19 '17 at 17:18
  • $\begingroup$ @Martin that seems to be off topic for CV. $\endgroup$ – Haitao Du May 19 '17 at 17:21
  • $\begingroup$ Thanks for the heads up, this could be why i cannot find the answer to this problem anywhere. $\endgroup$ – Martin May 19 '17 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.