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

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Azure Text Analytics for Medical Search Engine Deployment
Microsoft Azure Project - Use Azure text analytics cognitive service to deploy a machine learning model into Azure Databricks

MLOps using Azure Devops to Deploy a Classification Model
In this MLOps Azure project, you will learn how to deploy a classification machine learning model to predict the customer's license status on Azure through scalable CI/CD ML pipelines.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.