How to do it...

Let's see how to build a recurrent neural network for sequential data analysis:

  1. Create a new Python file, and import the following packages (the full code is given in the recurrent_network.py file that is provided to you):
import numpy as np 
import matplotlib.pyplot as plt 
import neurolab as nl 
  1. Define a function to create a waveform, based on input parameters:
def create_waveform(num_points): 
    # Create train samples 
    data1 = 1 * np.cos(np.arange(0, num_points)) 
    data2 = 2 * np.cos(np.arange(0, num_points)) 
    data3 = 3 * np.cos(np.arange(0, num_points)) 
    data4 = 4 * np.cos(np.arange(0, num_points)) 
  1. Create different amplitudes for each interval to create a random waveform:
 # Create varying amplitudes amp1 = np.ones(num_points) ...

Get Python Machine Learning Cookbook - Second Edition 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.