O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Step 1 loads the necessary packages--nnet for neural network modeling and caret for data partitioning. We also load devtools because we will be sourcing code using a web URL for printing the network.

Step 2 reads the file.

Step 3 partitions the data. Refer to the Creating random data partitions recipe from Chapter 2What's in There? - Exploratory Data Analysis for more details. We have set the random seed to enable you to match your results with those that we have displayed.

Step 4 builds the neural net model using the nnet function of the nnet package:

> fit <- nnet(MEDV/50 ~ ., data=bh[t.idx,], size=6, decay = 0.1, maxit = 1000, linout = TRUE) 

We divide our response variable by 50 to scale it to the range [01]. We pass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required