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
course content

Contenido del Curso

ML Introduction with scikit-learn

ML Introduction with scikit-learn

1. Machine Learning Concepts
2. Preprocessing Data with Scikit-learn
3. Pipelines
4. Modeling

bookEncode 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:

12345
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/penguins_imputed.csv') print(df.head())
copy

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

Tarea
test

Swipe to show code editor

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.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 8
toggle bottom row

bookEncode 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:

12345
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/penguins_imputed.csv') print(df.head())
copy

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

Tarea
test

Swipe to show code editor

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.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 8
toggle bottom row

bookEncode 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:

12345
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/penguins_imputed.csv') print(df.head())
copy

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

Tarea
test

Swipe to show code editor

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.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

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:

12345
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a65bbc96-309e-4df9-a790-a1eb8c815a1c/penguins_imputed.csv') print(df.head())
copy

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

Tarea
test

Swipe to show code editor

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.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 2. Capítulo 8
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt