What is Classification Dataset in PyBrain

This recipe explains what is Classification Dataset in PyBrain

Recipe Objective - What is Classification Dataset in PyBrain?

This dataset is used primarily to solve classification problems. It accepts input, target field, and an additional field called "Class," an automatic backup of the specified targets. For example, the output will be 1 or 0, or the output will be grouped with values based on the given inputs; belongs to a certain class.

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 on the iris dataset -

# Importing all the necessary libraries
from sklearn import datasets
import matplotlib.pyplot as plt
from pybrain.datasets import ClassificationDataSet
from pybrain.utilities import percentError
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.structure.modules import SoftmaxLayer
from numpy import ravel

# Loading iris dataset from sklearn datasets
iris = datasets.load_iris()

# Defining feature variables and target variable
X_data = iris.data
y_data = iris.target

# Defining classification dataset model
classification_dataset = ClassificationDataSet(4, 1, nb_classes=3)

# Adding sample into classification dataset
for i in range(len(X_data)):
  classification_dataset.addSample(ravel(X_data[i]), y_data[i])

# Spilling data into testing and training data with the ratio 7:3
testing_data, training_data = classification_dataset.splitWithProportion(0.3)

# Classification dataset for test data
test_data = ClassificationDataSet(4, 1, nb_classes=3)

# Adding sample into testing classification dataset
for n in range(0, testing_data.getLength()):
   test_data.addSample( testing_data.getSample(n)[0], testing_data.getSample(n)[1] )

# Classification dataset for train data
train_data = ClassificationDataSet(4, 1, nb_classes=3)

# Adding sample into training classification dataset
for n in range(0, training_data.getLength()):
   train_data.addSample( training_data.getSample(n)[0], training_data.getSample(n)[1] )

test_data._convertToOneOfMany()
train_data._convertToOneOfMany()

# Building network with outclass as SoftmaxLayer on training data
build_network = buildNetwork(train_data.indim, 4, train_data.outdim, outclass=SoftmaxLayer)

# Building a backproptrainer on training data
trainer = BackpropTrainer(build_network, dataset=train_data, learningrate=0.01, verbose=True)

# 20 iterations on training data
trainer.trainEpochs(20)

# Testing data
print('Error percentage on testing data=>',percentError(trainer.testOnClassData(dataset=test_data), test_data['class']))

Output -
Total error:  0.0892390931641
Total error:  0.0821479733597
Total error:  0.0759327938967
Total error:  0.0722385583142
Total error:  0.0690818068826
Total error:  0.0667645311923
Total error:  0.0647079622731
Total error:  0.0630345245312
Total error:  0.0608030839912
Total error:  0.0595356750412
Total error:  0.0586635639408
Total error:  0.0573043661487
Total error:  0.0559188704413
Total error:  0.0548155819544
Total error:  0.0535537679931
Total error:  0.0527051106108
Total error:  0.0515783629912
Total error:  0.0501025301423
Total error:  0.0499123823243
Total error:  0.0482250742606
Error percentage on testing data=> 20.0

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

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

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.

Linear Regression Model Project in Python for Beginners Part 1
Machine Learning Linear Regression Project in Python to build a simple linear regression model and master the fundamentals of regression for beginners.

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

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

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.

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.