How to build a Recurrent Network using PyBrain

This recipe helps you build a Recurrent Network using PyBrain

Recipe Objective - How to build a Recurrent Network using PyBrain?

Recurrent networks are similar to the feed-through network; the only difference is that you must remember the data at each step. The history of each step must be saved.

For more related projects -

https://www.projectpro.io/projects/data-science-projects/deep-learning-projects
https://www.projectpro.io/projects/data-science-projects/keras-deep-learning-projects

Let's try to build a recurrent network -

# Importing libraries
from pybrain.structure import RecurrentNetwork
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection

# Building feed forward network model
recurrent_network = RecurrentNetwork()

# Making layer for input => 3 , hidden=> 3 and output=>1
input_layer = LinearLayer(3)
hidden_layer = SigmoidLayer(3)
output_layer = LinearLayer(1)

# Adding the layer to feedforward network
recurrent_network.addInputModule(input_layer)
recurrent_network.addModule(hidden_layer)
recurrent_network.addOutputModule(output_layer)

# Making connection between input ,hidden and output
input_to_hidden = FullConnection(input_layer, hidden_layer)
hidden_to_output = FullConnection(hidden_layer, output_layer)

# Adding connection to the network
recurrent_network.addConnection(input_to_hidden)
recurrent_network.addConnection(hidden_to_output)

# Add recurrent connection from hidden to hidden layers
recurrent_network.addRecurrentConnection(FullConnection(hidden_layer, hidden_layer))

# Sorting modules
recurrent_network.sortModules()

# Printing network
print(recurrent_network)

# Activating network by passing 3 input values
print("Output => ",recurrent_network.activate((1, 1, 1)))

# Clearing the history of the network by calling reset method
recurrent_network.reset()

Output -
RecurrentNetwork-7
   Modules:
    [<LinearLayer 'LinearLayer-4'>, <SigmoidLayer 'SigmoidLayer-8'>, <LinearLayer 'LinearLayer-9'>]
   Connections:
    [<FullConnection 'FullConnection-5': 'LinearLayer-4' -> 'SigmoidLayer-8'>, <FullConnection 'FullConnection-6': 'SigmoidLayer-8' -> 'LinearLayer-9'>]
   Recurrent Connections:
    [<FullConnection 'FullConnection-3': 'SigmoidLayer-8' -> 'SigmoidLayer-8'>]
Output =>  [0.1918294]

In this way, we can build a recurrent network using pybrain.

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Tensorflow Transfer Learning Model for Image Classification
Image Classification Project - Build an Image Classification Model on a Dataset of T-Shirt Images for Binary Classification

End-to-End ML Model Monitoring using Airflow and Docker
In this MLOps Project, you will learn to build an end to end pipeline to monitor any changes in the predictive power of model or degradation of data.

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.