How to use connections to build a network in PyBrain

This recipe helps you use connections to build a network in PyBrain

Recipe Objective - How to use connections to build a network in PyBrain?

Connection works similarly to a layer; the only difference is that it moves data from node to node on a network.

For more related projects -

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

Let's try to build a network using connections-

# Importing libraries
from pybrain.structure import FeedForwardNetwork
from pybrain.structure import LinearLayer, SigmoidLayer

# Building feed forward network model
feed_forward_network = FeedForwardNetwork()

# 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
feed_forward_network.addInputModule(input_layer)
feed_forward_network.addModule(hidden_layer)
feed_forward_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
feed_forward_network.addConnection(input_to_hidden)
feed_forward_network.addConnection(hidden_to_output)
feed_forward_network.sortModules()

# Printing network
print(feed_forward_network)

Output -
FeedForwardNetwork-14
   Modules:
    [<LinearLayer 'LinearLayer-11'>, <SigmoidLayer 'SigmoidLayer-15'>, <LinearLayer 'LinearLayer-16'>]
   Connections:
    [<FullConnection 'FullConnection-12': 'LinearLayer-11' -> 'SigmoidLayer-15'>, <FullConnection 'FullConnection-13': 'SigmoidLayer-15' -> 'LinearLayer-16'>]

In this way, we can use connections to build a network in pybrain.

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Build Portfolio Optimization Machine Learning Models in R
Machine Learning Project for Financial Risk Modelling and Portfolio Optimization with R- Build a machine learning model in R to develop a strategy for building a portfolio for maximized returns.

Multilabel Classification Project for Predicting Shipment Modes
Multilabel Classification Project to build a machine learning model that predicts the appropriate mode of transport for each shipment, using a transport dataset with 2000 unique products. The project explores and compares four different approaches to multilabel classification, including naive independent models, classifier chains, natively multilabel models, and multilabel to multiclass approaches.

Recommender System Machine Learning Project for Beginners-2
Recommender System Machine Learning Project for Beginners Part 2- Learn how to build a recommender system for market basket analysis using association rule mining.

Learn How to Build PyTorch Neural Networks from Scratch
In this deep learning project, you will learn how to build PyTorch neural networks from scratch.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

AWS MLOps Project for Gaussian Process Time Series Modeling
MLOps Project to Build and Deploy a Gaussian Process Time Series Model in Python on AWS

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python