0
votes

I have a data set of 10 variables, where 4 variables are continuous and 6 are categorical. The dependant variable is also a categorical variable whose values are "Yes" or "No". I understand that we would need to create dummy variables for the categorical variables. But how can I create the Neural Network model in R using neuralnet function with these dummy variables and continuous variables?

1

1 Answers

0
votes

You can use dummyVars from caret, below is an example where I convert some continuous variables to categorical:

library(neuralnet)
library(caret)
library(MASS)

data=MASS::Pima.te
data$glu = cut(data$glu,breaks=4,labels=1:4)
data$bmi = cut(data$bmi,breaks=3,labels=1:3)

dummy_model = dummyVars(type~.,data=data)
mat2 = data.frame(type=data$type,predict(dummy_model,data))

head(mat2)
  type npreg glu.1 glu.2 glu.3 glu.4 bp skin bmi.1 bmi.2 bmi.3   ped age
1  Yes     6     0     0     1     0 72   35     1     0     0 0.627  50
2   No     1     1     0     0     0 66   29     1     0     0 0.351  31
3   No     1     1     0     0     0 66   23     1     0     0 0.167  21
4  Yes     3     1     0     0     0 50   32     1     0     0 0.248  26
5  Yes     2     0     0     0     1 70   45     1     0     0 0.158  53



fit2 = neuralnet(type~.,data=mat2)