Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Encode Categorical Variables | Preprocessing Data with Scikit-learn
ML Introduction with scikit-learn

Encode Categorical VariablesEncode Categorical Variables

To summarize the previous three chapters, here is a table showing what encoder you should use.

ColumnEncoder
X, ordinal valuesOrdinalEncoder
X, nominal valuesOneHotEncoder
yLabelEncoder

In this challenge, you have the Penguins dataset file (with no missing values).
You need to deal with all the categorical values, including the target ('species' column).
Here is the reminder of the data you will work with:

Here 'island' and 'sex' are categorical features and 'species' is a categorical target

Task

Encode all the categorical values. For this, you need to choose the correct encoder for the 'island', and 'sex' columns and follow the steps.

  1. Import the correct encoder for features.
  2. Initialize the features encoder object.
  3. Fit and transform the categorical feature columns using the feature_enc object.
  4. Fit and transform the target using LabelEncoder.

Everything was clear?

Section 2. Chapter 8
toggle bottom row
course content

Course Content

ML Introduction with scikit-learn

Encode Categorical VariablesEncode Categorical Variables

To summarize the previous three chapters, here is a table showing what encoder you should use.

ColumnEncoder
X, ordinal valuesOrdinalEncoder
X, nominal valuesOneHotEncoder
yLabelEncoder

In this challenge, you have the Penguins dataset file (with no missing values).
You need to deal with all the categorical values, including the target ('species' column).
Here is the reminder of the data you will work with:

Here 'island' and 'sex' are categorical features and 'species' is a categorical target

Task

Encode all the categorical values. For this, you need to choose the correct encoder for the 'island', and 'sex' columns and follow the steps.

  1. Import the correct encoder for features.
  2. Initialize the features encoder object.
  3. Fit and transform the categorical feature columns using the feature_enc object.
  4. Fit and transform the target using LabelEncoder.

Everything was clear?

Section 2. Chapter 8
toggle bottom row
some-alt