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…

  1. Create a new Python file, and import the following packages:
    import numpy as np
    import matplotlib.pyplot as plt
    import neurolab as nl 
  2. 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:]
  3. Let's plot the input data:
    # Plot input data plt.figure() plt.scatter(data[:,0], data[:,1]) plt.xlabel('X-axis') ...

Get Python Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.