Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Preprocessing Pipeline | Section
Data Preprocessing and Feature Engineering

bookChallenge: Preprocessing Pipeline

Aufgabe

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:

  1. Load the dataset using sns.load_dataset("titanic").
  2. Handle missing values:
    • Numeric columns → fill with mean.
    • Categorical columns → fill with mode.
  3. Encode the categorical features sex and embarked using pd.get_dummies().
  4. Scale numeric columns age and fare using StandardScaler.
  5. Create a new feature family_size = sibsp + parch + 1.
  6. Combine all transformations into a function called preprocess_titanic(data) that returns the final processed DataFrame.
  7. Assign the processed dataset to a variable called processed_data.

Print the first 5 rows of the final DataFrame.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 12
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

close

bookChallenge: Preprocessing Pipeline

Swipe um das Menü anzuzeigen

Aufgabe

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:

  1. Load the dataset using sns.load_dataset("titanic").
  2. Handle missing values:
    • Numeric columns → fill with mean.
    • Categorical columns → fill with mode.
  3. Encode the categorical features sex and embarked using pd.get_dummies().
  4. Scale numeric columns age and fare using StandardScaler.
  5. Create a new feature family_size = sibsp + parch + 1.
  6. Combine all transformations into a function called preprocess_titanic(data) that returns the final processed DataFrame.
  7. Assign the processed dataset to a variable called processed_data.

Print the first 5 rows of the final DataFrame.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 12
single

single

some-alt