9.8 HOW TO USE NEURAL NETWORKS IN R
First, read in the Framingham_training data set as fram_train, and convert the binary and ordinal variables Death and Sex to factors.
fram_train$Death <‐ as.factor(fram_train$Death)
fram_train$Sex <‐ as.factor(fram_train$Sex)
Perform min–max standardization on the Age variable
fram_train$Age.mm <‐ (fram_train$Age ‐ min(fram_train$Age)) /
(max(fram_train$Age) ‐ min(fram_train$Age))
Install the nnet and NeuralNetTools packages, and open both packages.
install.packages(“nnet”); install.packages("NeuralNetTools")
library(nnet); library(NeuralNetTools)
Run the neural network algorithm.
nnet01 <‐ nnet(Death ~ Sex + Age.mm, data = fram_train, size = 1)
Note the formula structure, with the target variable Death on the left side of the tilde, and the two predictor variables Sex and Age on the right side. The data = fram_train input specifies where the three variables...