Constructing a multilayer neural network
In order to enable higher accuracy, we need to give more freedom to the neural network. This means that a neural network needs more than one layer to extract the underlying patterns in the training data. Let's create a multilayer neural network to achieve that.
Create a new Python file and import the following packages:
import numpy as np import matplotlib.pyplot as plt import neurolab as nl
In the previous two sections, we saw how to use a neural network as a classifier. In this section, we will see how to use a multilayer neural network as a regressor. Generate some sample data points based on the equation y = 3x^2 + 5 and then normalize the points:
# Generate some training data min_val = -15 max_val = 15 num_points = 130 x = np.linspace(min_val, max_val, num_points) y = 3 * np.square(x) + 5 y /= np.linalg.norm(y)
Reshape the above variables to create a training dataset:
# Create data and labels data = x.reshape(num_points, 1)...