Building a single layer neural network
Now that we know how to create a perceptron, let's create a single layer neural network. A single layer neural network consists of multiple neurons in a single layer. Overall, we will have an input layer, a hidden layer, and an output layer.
How to do it…
- Create a new Python file, and import the following packages:
import numpy as np import matplotlib.pyplot as plt import neurolab as nl
- We will use the data in the
data_single_layer.txt
file. Let's load this:# Define input data input_file = 'data_single_layer.txt' input_text = np.loadtxt(input_file) data = input_text[:, 0:2] labels = input_text[:, 2:]
- Let's plot the input data:
# Plot input data plt.figure() plt.scatter(data[:,0], data[:,1]) plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Input data')
- Let's extract the minimum and maximum values:
# Min and max values for each dimension x_min, x_max = data[:,0].min(), data[:,0].max() y_min...