Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Encoding Categorical Variables | Section
Machine Learning Foundations with Scikit-Learn
Sección 1. Capítulo 13
single

single

bookChallenge: Encoding Categorical Variables

Desliza para mostrar el menú

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

In this challenge, you work with the penguins dataset (no missing values). All categorical features — including the target 'species' — must be encoded for ML use.

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

Keep in mind that 'island' and 'sex' are categorical features and 'species' is a categorical target.

Tarea

Desliza para comenzar a programar

You are given a DataFrame df. Encode all categorical columns:

  1. Import OneHotEncoder and LabelEncoder from sklearn.preprocessing.
  2. Split the data into X (features) and y (target).
  3. Create a OneHotEncoder and apply it to the 'island' and 'sex' columns in X.
  4. Replace those original columns with their encoded versions.
  5. Use LabelEncoder on the 'species' column to encode y.

Solución

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 1. Capítulo 13
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt