Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Encoding Categorical Variables | Section
Machine Learning Foundations with Scikit-Learn
Секція 1. Розділ 13
single

single

bookChallenge: Encoding Categorical Variables

Свайпніть щоб показати меню

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.

Завдання

Проведіть, щоб почати кодувати

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.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 13
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt