Pybrain is an open source, machine learning library that stands for Python-Based Reinforcement Learning, Artificial Intelligence, and Neural Network Library. It provides some
simple to use training algorithms for datasets and help in different machine learning tasks.
It backs up neural networks like convolutional neural networks, recurrent neural networks, feed-forward networks, etc.
It supports various datasets that comprise classification dataset and supervised dataset.
It cannot separately visualize the testing data by itself. It works with various frameworks like pyplot or matplotlib to visualize the data.
When a network is created, it gets trained on the training data provided to it. Whether the network is properly trained will be based on the prediction of test data. Pybrain uses two main concepts - TrainUntil Convergence and Backprop Trainer.
TrainUntilConvergence: It trains the module of the dataset until it converges.
The parameter of a module is trained by this model using a classification or a supervised dataset by backpropagation of errors.
First we have raw data, then after pre-processing, the data can be used by the Pybrain library.
The major flow of the Pybrain library begins when the dataset is divided into train and test datasets.
After the division of datasets, the network gets created and the network and dataset are handed over to the trainer.
The model is trained by the trainer on the network and then the classification of the output is done as the trained error and validation error. After this classification the error is visualized.
At the end, the tested data is validated to make sure the output matches the train data.
Any network is made of different modules, and the modules are connected using various connections. We will be talking about two things further:
Creating a Network
Analyzing a Network
There is an easy way to build the network, shown below:
Code:
1
2
3
From pybrain.tools.shortcuts
import buildNetwork
Net = buildNetwork(2, 3, 1)
The above call returns a net that has two input units, three hidden and only one output unit of neuron.
The network, when created, is then only initialized with random values.
Code:
1
2
Net.activate([2, 1])
Array([-0.98646726])
While analyzing a network, one can access various layers in the network separately as follows:
Code:
1 2 3 4 5
>>> Network[‘hidden0’] < SigmoidLayer‘ hidden’ > Network[‘bias’] < BiasUnit‘ bias’ >
Input data that is given to test is called the dataset. After that it is validated and then the network is trained. The dataset that needs to be used relies on the machine learning use case. We will discuss two things about the dataset below:
Create a dataset
Putting data to dataset
Pybrain.datasets: This package is used to create a dataset using Pybrain.
Supervised dataset, classification dataset, and sequential dataset are the datasets classes that are supported by Pybrain. Below we will be using a supervised dataset to create a new dataset.
A supervised dataset needs two things - input and target. Let’s have a look at the code below.
Code:
1
2
3
4
From pybrain.datasets
import SupervisedDataSet
Create_data = SupervisedDataSet(3, 1)
Print(Create_data)
Output:
Input: dim(0,3)
[]
Target: dim(0,1)
[]
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from pybrain.datasets
import SupervisedDataset
create_dataset = SupervisedDataSet(2, 1)
Model_Xor = [
[(0, 0), (0, )],
[(0, 1), (1, )],
[(1, 0), (1, )],
[(1, 1), (0, )],
]
For input, target in Model_Xor:
Create_dataset.addSample(input, target)
print(“Input is below: ”)
print(sds[‘input’])
print(“\nTarget is as follows: ”)
print(sds[‘target’])
Output:
Input is below:
[[ 0. 0.]
[0. 1.]
[1. 0.]
[1. 1.]]
Target is as follows:
[[0.]
[1.]
[1.]
[0. ]]
It is an open source machine learning library that is simple to use for any beginner in the field of machine learning.
Pybrain works smoothly with various other Python libraries.
Pybrain works well with different neural networks such as convolutional neural networks, recurrent networks, etc.
Pybrain permits us to use other datasets from various libraries.
As it is open source, there is a forum page or no help in case there is any issue.
Updates of Pybrain are not recent.