1. Learn
  2. /
  3. Courses
  4. /
  5. Feature Engineering for Machine Learning in Python

Connected

Exercise

One-hot encoding and dummy variables

To use categorical variables in a machine learning model, you first need to represent them in a quantitative way. The two most common approaches are to one-hot encode the variables using or to use dummy variables. In this exercise, you will create both types of encoding, and compare the created column sets. We will continue using the same DataFrame from previous lesson loaded as so_survey_df and focusing on its Country column.

Instructions 1/2

undefined XP
  • 1

    One-hot encode the Country column, adding "OH" as a prefix for each column.

  • 2

    Create dummy variables for the Country column, adding "DM" as a prefix for each column.