Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Encoding Categorical Variables | Section
/
Foundations of Machine Learning
セクション 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

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt