Visualizing the neural network

To visualize a neural network with hidden layers, we will use the neuralnet function. For illustration, two hidden layers with 10 and 5 units will be used in this example. The input layer has 13 nodes based on 13 independent variables. The output layer has only one node for the target variable, medv. The code used is as follows:

# Neural network
n <- neuralnet(medv~crim+zn+indus+chas+nox+rm+age+dis+rad+tax+ptratio+b+lstat,
data = data,
hidden = c(10,5),
linear.output = F,
lifesign = 'full',
rep=1)

# Plot
plot(n, col.hidden = "darkgreen",
col.hidden.synapse = 'darkgreen',
show.weights = F,
information = F,
fill = "lightblue")

As shown in the preceding code, the result is saved in n, and it is then used for plotting the architecture of the neural network, as shown in the following diagram:

As you can see from the preceding diagram, the input layer has 13 nodes for 13 independent variables. There are two hidden layers: the first hidden layer has 10 nodes and the second hidden layer has 5 nodes. Each node in the hidden layer is connected to all the nodes in the previous and the following layer. The output layer has one node for the response variable, medv.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset