Challenge: Preprocessing Pipeline
Taak
Swipe to start coding
You are given the Titanic dataset from the seaborn library.
Your task is to build a complete preprocessing pipeline that performs all essential data transformations used before machine learning.
Follow these steps:
- Load the dataset using
sns.load_dataset("titanic"). - Handle missing values:
- Numeric columns → fill with mean.
- Categorical columns → fill with mode.
- Encode the categorical features
sexandembarkedusingpd.get_dummies(). - Scale numeric columns
ageandfareusingStandardScaler. - Create a new feature
family_size = sibsp + parch + 1. - Combine all transformations into a function called
preprocess_titanic(data)that returns the final processed DataFrame. - Assign the processed dataset to a variable called
processed_data.
Print the first 5 rows of the final DataFrame.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 12
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 8.33
Challenge: Preprocessing Pipeline
Veeg om het menu te tonen
Taak
Swipe to start coding
You are given the Titanic dataset from the seaborn library.
Your task is to build a complete preprocessing pipeline that performs all essential data transformations used before machine learning.
Follow these steps:
- Load the dataset using
sns.load_dataset("titanic"). - Handle missing values:
- Numeric columns → fill with mean.
- Categorical columns → fill with mode.
- Encode the categorical features
sexandembarkedusingpd.get_dummies(). - Scale numeric columns
ageandfareusingStandardScaler. - Create a new feature
family_size = sibsp + parch + 1. - Combine all transformations into a function called
preprocess_titanic(data)that returns the final processed DataFrame. - Assign the processed dataset to a variable called
processed_data.
Print the first 5 rows of the final DataFrame.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 12
single