Putting it all together
Putting all the concepts we have learned so far together, we will see how to build a neural network from scratch. We will understand how the neural network learns to perform the XOR gate operation. The XOR gate returns 1 only when exactly only one of its inputs is 1, else it returns 0, as shown in Table 7.1:
Table 7.1: XOR operation
Building a neural network from scratch
To perform the XOR gate operation, we build a simple two-layer neural network, as shown in the following diagram. As you can see, we have an input layer with two nodes, a hidden layer with five nodes and an output layer comprising one node:
Figure 7.13: ANN
We will understand step-by-step how a neural network learns the XOR logic:
- First, import the libraries:
import numpy as np import matplotlib.pyplot as plt %matplotlib inline
- Prepare the data as shown in the preceding XOR table:
X = np.array([ [0, 1], [1, 0], [1, 1],[0...