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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

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.

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

Stock Price Prediction Project using LSTM and RNN
Learn how to predict stock prices using RNN and LSTM models. Understand deep learning concepts and apply them to real-world financial data for accurate forecasting.

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.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

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

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.