What is Supervised Dataset in PyBrain

This recipe explains what is Supervised Dataset in PyBrain

Recipe Objective - What is Supervised Dataset in PyBrain?

Datasets are data that is available for testing, validation, and networking training.
SupervisedDataSet consists of input and target fields. It is the simplest form of data set and is used primarily for supervised learning tasks.

For more related projects -

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

Let's try to create an AND truth table. The inputs given are like a two-dimensional array, and we get 1 output. Here the input becomes the size, and the destination becomes the output, which is 1. So the inputs that are used for our dataset are 2,1.

Complete Guide to Tensorflow for Deep Learning with Python for Free

# Importing libraries
from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import TanhLayer
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer

# Create a network with two inputs, two hidden, and one output
network = buildNetwork(2, 2, 1, bias=True, hiddenclass=TanhLayer)

# Create a dataset that matches network input and output sizes:
and_gate = SupervisedDataSet(2, 1)

# Create a dataset to be used for testing.
and_testing_data = SupervisedDataSet(2, 1)

# Add input and target values to dataset values for AND truth table
and_gate.addSample((0, 0), (0,))
and_gate.addSample((0, 1), (0,))
and_gate.addSample((1, 0), (0,))
and_gate.addSample((1, 1), (1,))

# Add input and target values to dataset values for AND truth table
and_testing_data.addSample((0, 0), (0,))
and_testing_data.addSample((0, 1), (0,))
and_testing_data.addSample((1, 0), (0,))
and_testing_data.addSample((1, 1), (1,))

#Training the network with dataset and_gate.
backprop_trainer = BackpropTrainer(network, and_gate)

# 5000 iteration on training data.
for iteration in range(5000):
  backprop_trainer.train()

# Testing data
backprop_trainer.testOnData(dataset=and_testing_data, verbose = True)

Output -
Testing on data:
('out:    ', '[-0.102]')
('correct:', '[0     ]')
error:  0.00516301
('out:    ', '[0.06  ]')
('correct:', '[0     ]')
error:  0.00179703
('out:    ', '[0.06  ]')
('correct:', '[0     ]')
error:  0.00180398
('out:    ', '[0.979 ]')
('correct:', '[1     ]')
error:  0.00022535
('All errors:', [0.00516301203548386, 0.0017970306041855497, 0.0018039844580629869, 0.00022534953160662042])
('Average error:', 0.0022473441573347542)
('Max error:', 0.00516301203548386, 'Median error:', 0.0018039844580629869)
0.0022473441573347542

In this way, we can use a supervised dataset 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

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

Loan Default Prediction Project using Explainable AI ML Models
Loan Default Prediction Project that employs sophisticated machine learning models, such as XGBoost and Random Forest and delves deep into the realm of Explainable AI, ensuring every prediction is transparent and understandable.

Build a Review Classification Model using Gated Recurrent Unit
In this Machine Learning project, you will build a classification model in python to classify the reviews of an app on a scale of 1 to 5 using Gated Recurrent Unit.

Word2Vec and FastText Word Embedding with Gensim in Python
In this NLP Project, you will learn how to use the popular topic modelling library Gensim for implementing two state-of-the-art word embedding methods Word2Vec and FastText models.

LLM Project to Build and Fine Tune a Large Language Model
In this LLM project for beginners, you will learn to build a knowledge-grounded chatbot using LLM's and learn how to fine tune it.

End-to-End Speech Emotion Recognition Project using ANN
Speech Emotion Recognition using RAVDESS Audio Dataset - Build an Artificial Neural Network Model to Classify Audio Data into various Emotions like Sad, Happy, Angry, and Neutral

Build a Multi Class Image Classification Model Python using CNN
This project explains How to build a Sequential Model that can perform Multi Class Image Classification in Python using CNN

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.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

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.