One hot Encoding with nominal categorical features in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

One hot Encoding with nominal categorical features in Python?

One hot Encoding with nominal categorical features in Python?

One hot Encoding with nominal categorical features in Python

3
This python source code does the following: 1. Converts categorical into numerical types. 2. Loads the important libraries and Implements label binarizer. 3. Creates your own numpy feature matrix.
In [1]:
## One hot Encoding with nominal categorical features in Python 
def Kickstarter_Example_37():
    print()
    print(format('How to One hot Encode with nominal categorical features in Python', '*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # Load libraries
    import numpy as np
    from sklearn.preprocessing import LabelBinarizer

    # Create Data With One Class Label
    # Create NumPy array
    x = np.array([['Texas'],
                  ['California'],
                  ['Texas'],
                  ['Delaware'],
                  ['Texas']])

    # One-hot Encode Data (Method 1)

    # Create LabelBinzarizer object
    one_hot = LabelBinarizer()

    # One-hot encode data
    print(); print(one_hot.fit_transform(x))

    # View Column Headers
    # View classes
    print(); print(one_hot.classes_)

Kickstarter_Example_37()
********How to One hot Encode with nominal categorical features in Python*********

[[0 0 1]
 [1 0 0]
 [0 0 1]
 [0 1 0]
 [0 0 1]]

['California' 'Delaware' 'Texas']

Relevant Projects

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.