What is SoftmaxLayer in PyBrain

This recipe explains what is SoftmaxLayer in PyBrain

Recipe Objective - What is SoftmaxLayer in PyBrain?

Pybrain provides mainly two layers: TanhLayer and SoftmaxLayer. SoftmaxLayer implements a softmax distribution over the input.

For more related projects -

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

Let's try to build a network using SoftmaxLayer -

# Importing libraries
from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import SoftmaxLayer
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=SoftmaxLayer)

# 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.008]')
('correct:', '[0     ]')
error:  0.00003074
('out:    ', '[0.334 ]')
('correct:', '[0     ]')
error:  0.05586374
('out:    ', '[0.334 ]')
('correct:', '[0     ]')
error:  0.05586374
('out:    ', '[0.334 ]')
('correct:', '[1     ]')
error:  0.22160712
('All errors:', [3.07437732734914e-05, 0.055863744147581454, 0.05586374414543854, 0.22160712372514815])
('Average error:', 0.08334133894786042)
('Max error:', 0.22160712372514815, 'Median error:', 0.055863744147581454)
0.08334133894786042

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

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.

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.

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 Text Classification Model with Attention Mechanism NLP
In this NLP Project, you will learn to build a multi class text classification model with attention mechanism.

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

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.

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

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

Linear Regression Model Project in Python for Beginners Part 2
Machine Learning Linear Regression Project for Beginners in Python to Build a Multiple Linear Regression Model on Soccer Player Dataset.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.