Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Preprocessing the Dataset | Core Concepts
/
Cluster Analysis with Python
セクション 2.  6
single

single

bookChallenge: Preprocessing the Dataset

メニューを表示するにはスワイプしてください

タスク

スワイプしてコーディングを開始

You are given a synthetic dataset stored in the data variable. Your task is to handle missing values and encode categorical features properly.

Follow these steps:

  • Replace missing values in the 'Age' column with the mean value of this column. Overwrite the original column with the result.
  • Create an instance of OneHotEncoder and store it in the city_encoder variable. Make sure to specify drop='first' to avoid the dummy variable trap.
    • By default, this encoder returns a sparse matrix. To make it compatible with Pandas later, set the parameter sparse_output=False (or sparse=False for older versions) during initialization, OR append .toarray() when you transform the data.
  • Encode the values in the 'City' column using city_encoder.fit_transform() and store the resulting array in the city_encoded variable.
  • Create an instance of OrdinalEncoder and store it in the income_encoder variable. Since the data has a natural hierarchy, explicitly define the order using the categories parameter (note that 'Low' < 'Middle' < 'High').
  • Encode the values in the 'Income' column using income_encoder and overwrite the original 'Income' column with the result.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 2.  6
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt