• Welcome !
  • Mail us: contact@analytickast.com
Analytickast.com Analytickast.com
  • Home
  • Blog
  • Coaching
    • Course Dashboard
    • Instructor Registration
    • Student Registration
  • Shop Now
  • Contact Us
  • My account
    • Cart
    • Checkout
  • Log In

Signup

Handling Character Data for Machine Learning

Handling Character Data for Machine Learning

Learn about different methods of encoding character attributes for creating useful machine learning models, including frequency-based encoding and hash encoding.

Creating machine learning projects with numerical attributes is easy. Most of the open-source data available for building ML models has numerical attributes. However, when we deal with enterprise data, the case is a bit different. Character or string data dominate the dataset in enterprises, making it hard to create a very accurate machine learning model. We have to clean messy strings, pull strings apart, and extract useful strings embedded in a text to bring it into a form that can be used in a machine learning pipeline.

We will cover this discussion in two parts. The first piece will focus on different methods of encoding character attributes for creating useful machine learning models. The second part will focus on manipulating and extracting useful text out of the messy strings using R.

Let’s speak about categorical data. Categorical data are variables that have a finite number of label values. They cannot be continuous, and generally, the values represent a fixed category. Based on the nature of categorical attributes, they can either be nominal or ordinal. When there is a natural ordering of values for categorical data, it is termed as ordinal. For example, categorical values such as high, medium, and low are ordered values. When we cannot derive any relationship or order from the categorical values, it is termed as nominal. For example, colors such as red, yellow, and green have no order. The values in a categorical attribute are referred mostly as classes or categories.

Most of the time, we require categorical attributes to be converted to a numeric format in order for the machine learning algorithm to work. Even for algorithms like decision trees where there is no requirement for encoding the values, properly encoded categorical attributes outperform the latter. We discuss below some of the techniques to encode the categorical attributes:

  1. Label encoding: As the name suggests, label encoding transforms labels into numerical labels. Label encoding is suited better for the ordinal type of categorical data. The labels are always in between 0 and n-1, where n is the number of classes.
  2. One hot encoding: This method is also termed as dummy coding. Using this method, dummy columns are created for each class of a categorical attribute. For each dummy attribute, the presence of the class is represented by 1 and its absence is represented by 0.
  3. Frequency-based encoding: Using this method, the occurrence frequency is calculated for each class out of the total classes. The corresponding relative frequency is assigned as encoded values for the classes.
  4. Target mean encoding: It can only be used for supervised machine learning problem where there is a target or response attribute. Each class of the categorical input attribute is encoded as a function of the mean of the target.
  5. Binary encoding: The classes are first converted to the numeric format, and then they are converted to their equivalent binary strings. The binary digits are then split into separate columns.
  6. Hash encoding: This method is also popularly known as feature hashing. A hash function is used to map data to a number. This method may map different classes to the same bucket, but is useful when there are hundreds of classes/categories present for an attribute.

Apart from these six techniques, there are some more like sum, polynomial, backward difference, and helmert encoding for categorical attributes. You can find more information about these on Will’s blog. All of the techniques are also implemented in Python and are available in the package category_encoders. One can pip install category_encoders to install the package and try to use the different encoding methods for a Machine Learning project. The scikit-learn categorical encoding GitHub page has more information about various functions in the package.

There are some more methods, like leaving one out method for encoding, and you can refer the below videos to know about this technique and feature engineering in general.

  • Learn Kaggle Techniques
  • Automatic Feature Engineering With Driverless AI
Categories: Machine Learning
Prev Post
Next Post

Add your Comment

Recent Posts

  • Insights on Data Science Automation for Big Data and IoT Environments
  • The Changing Landscape: Data Science Trends
  • Streamline the Machine Learning Process Using Apache Spark ML Pipelines
  • Dive Deep Into Deep Learning
  • CEP Patterns for Stream Analytics

Recent Comments

    Archives

    • June 2020

    Post Categories

    • Business Analytics
    • Machine Learning
    • Popular Content

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    About AnalyticKast

    Author

    Our goal is to provide easy access to people on data technologies related information to thrive in this digital economy.

    Latest Posts

    Insights on Data Science Automation for Big Data and IoT Environments

    Insights on Data Science Automation for Big Data and IoT Environments

    June 30, 2020

    The Changing Landscape: Data Science Trends

    June 30, 2020

    Streamline the Machine Learning Process Using Apache Spark ML Pipelines

    June 30, 2020

    About Analytickast

    One-stop knowledge services platform that supports individuals connect the dots between technologies and management to build data products. Our goal is to provide easy access to people on data technologies related information to thrive in this digital economy.

    Blogs

    • Business Analytics
    • Machine Learning
    • Popular Content

    Quick Links

    • Home
    • Blog
    • Coaching
    • Shop Now
    • Contact Us
    • My account
    • Log In

    Our Videos

    All Rights Reserved © 2020. - www.analytickast.com .

    • Privacy Policy
    • Legal Disclaimer
    • Terms of Use

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.