How to encode ordinal categorical features in Python?
DATA MUNGING

How to encode ordinal categorical features in Python?

How to encode ordinal categorical features in Python?

This recipe helps you encode ordinal categorical features in Python

0
This python source code does the following: 1. Creates custom pandas dataframe 2. Creates a mapping list for encoding 3. Uses "replace" function to manually encode the categorical variables
In [1]:
## How to encode ordinal categorical features in Python 
def Kickstarter_Example_31():
    print()
    print(format('How to encode ordinal categorical features in Python', '*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # Load library
    import pandas as pd

    # Create features
    df = pd.DataFrame({'Score': ['Low', 'Low', 'Medium', 'Medium', 'High']})

    # View data frame
    print(); print(df)

    # Create Scale Map
    scale_mapper = {'Low':1, 'Medium':2, 'High':3}

    # Map feature values to scale
    df['Scale'] = df['Score'].replace(scale_mapper)

    # View data frame
    print(); print(df)

Kickstarter_Example_31()
***************How to encode ordinal categorical features in Python***************

    Score
0     Low
1     Low
2  Medium
3  Medium
4    High

    Score  Scale
0     Low      1
1     Low      1
2  Medium      2
3  Medium      2
4    High      3

Relevant Projects

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.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Anomaly Detection Using Deep Learning and Autoencoders
Deep Learning Project- Learn about implementation of a machine learning algorithm using autoencoders for anomaly detection.

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.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

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.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

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.