How to import the dataset from CSV file in PyBrain

This recipe helps you import the dataset from CSV file in PyBrain

Recipe Objective - How to import the dataset from a CSV file in PyBrain?

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 import the iris dataset from a CSV file-

# Importing pandas
import pandas as pd

# Importing Classification Data set
from pybrain.datasets import ClassificationDataSet

# Importing iris data from csv file
iris = pd.read_csv("iris.csv")

# Label encoding the target variable
iris['Species'] = iris['Species'].replace({'Iris-setosa':0,'Iris-versicolor':1,'Iris-virginica':2})

# Defining feature variables and target variable
iris = iris.values
X_data = iris[:,0:4]
y_data = iris[:,4]

# Creating classification dataset model by defining 4 inputs, 1 output and 3 classes.
classification_dataset = ClassificationDataSet(4, 1, nb_classes=3)

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

# Data loaded into classification dataset from sklearn datasets
print(classification_dataset)

Output -
input: dim(254, 4)
[[5.1 3.5 1.4 0.2]
 [4.9 3.  1.4 0.2]
 [4.7 3.2 1.3 0.2]
 [4.6 3.1 1.5 0.2]
 .
 .
 .
 .
 [2]
 [2]]

class: dim(0, 1)
[]

In this way, we can import the dataset from a CSV file in PyBrain.

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

Hands-On Approach to Master PyTorch Tensors with Examples
In this deep learning project, you will learn how to perform various operations on the building block of PyTorch : Tensors.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python