Adding Data to Dataset
In this part, we will discuss how we can add sample data to our data set.
Example:
In this example, we are creating an XOR truth table. The input passed is like a two-dimensional array and the output we get is 1. The input serves the purpose of size and the target acts as the output (equal is 1). So the inputs that are passed to our dataset are 2,1.
A | B | A XOR B |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 0 |
Python3
# Python program to create a dataset # using PyBrain # Importing supervised dataset from # pybrain.datasets from pybrain.datasets import SupervisedDataSet # Creating dataSet supervised_dataset = SupervisedDataSet( 2 , 1 ) # xor table xor_table = [ [( 0 , 0 ), ( 0 ,)], [( 0 , 1 ), ( 1 ,)], [( 1 , 0 ), ( 1 ,)], [( 1 , 1 ), ( 0 ,)], ] # Adding sample from xor_table into # supervised_dataset for input , target in xor_table: supervised_dataset.addSample( input , target) # Printing the input print ( "input: \n" , supervised_dataset[ 'input' ]) print ("") # Printing the target print ( "target: \n" , supervised_dataset[ 'target' ]) |
Output:
How to create a dataset using PyBrain?
In this article, we are going to see how to create a dataset using PyBrain.
Contact Us