How to import datasets using sklearn in PyBrain
Last Updated :
28 Feb, 2022
In this article, we will discuss how to import datasets using sklearn in PyBrain
Dataset: A Dataset is defined as the set of data that is can be used to test, validate, and train on networks. On comparing it with arrays, a dataset is considered more flexible and easy to use. A dataset resembles a 2-d array. Datasets are used in executing machine learning tasks.
Libraries need to be installed in our system are:
Syntax to install these libraries :
pip install sklearn pybrain
Example 1:
In this example, firstly we have imported packages datasets from sklearn library and ClassificationDataset from pybrain.datasets. Then we have loaded the digits dataset. In the next statement, we are defining feature variables and target variables. Then we are creating a classification dataset model by defining 64 inputs, 1 output, and 15 classes. Then, we have appended data to the created dataset.
Python3
from sklearn import datasets
from pybrain.datasets import ClassificationDataSet
loaded_digits = datasets.load_digits()
x_data, y_data = loaded_digits.data, loaded_digits.target
dataset = ClassificationDataSet( 64 , 1 , nb_classes = 15 )
for i in range ( len (x_data)):
dataset.addSample(x_data[i], y_data[i])
print (dataset)
|
Output:
Example 2:
In this example, firstly we have imported packages datasets from sklearn library and ClassificationDataset from pybrain.datasets. Then we have loaded the iris dataset. In the next statement, we are defining feature variables and target variables. Then we are creating a classification dataset model by defining 4 inputs, 1 output, and 2 classes. Then, we have appended data to the created dataset.
Python3
from sklearn import datasets
from pybrain.datasets import ClassificationDataSet
loaded_digits = datasets.load_iris()
x_data, y_data = loaded_digits.data, loaded_digits.target
dataset = ClassificationDataSet( 4 , 1 , nb_classes = 2 )
for i in range ( len (x_data)):
dataset.addSample(x_data[i], y_data[i])
print (dataset)
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...