Bird
Raised Fist0
ML Pythonml~20 mins

Why data preparation consumes most ML time in ML Python - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Data Preparation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does data cleaning take so much time in ML projects?

In machine learning, data cleaning is a major part of data preparation. Why does it usually take the most time?

ABecause raw data often has errors, missing values, and inconsistencies that need fixing before training.
BBecause training models requires a lot of computing power and time.
CBecause data cleaning involves writing complex algorithms to improve model accuracy.
DBecause data cleaning is automated and runs slowly on large datasets.
Attempts:
2 left
💡 Hint

Think about the quality of data collected from real-world sources.

🧠 Conceptual
intermediate
2:00remaining
What is the main reason feature engineering is time-consuming?

Feature engineering is a key step in data preparation. Why does it often consume a lot of time?

ABecause it only works on small datasets and needs manual scaling.
BBecause it involves training multiple models to select features.
CBecause it requires domain knowledge to create meaningful features from raw data.
DBecause it is fully automated and requires tuning many parameters.
Attempts:
2 left
💡 Hint

Think about how features relate to the problem you want to solve.

❓ Metrics
advanced
2:00remaining
Measuring data quality impact on model accuracy

You have two datasets: Dataset A is clean and Dataset B has 20% missing values. You train the same model on both. Which metric difference best shows the impact of data quality?

ADataset A precision: 0.5, Dataset B precision: 0.5
BDataset A loss: 0.2, Dataset B loss: 0.2
CDataset A training time: 10 minutes, Dataset B training time: 15 minutes
DDataset A accuracy: 90%, Dataset B accuracy: 70%
Attempts:
2 left
💡 Hint

Look for a metric that directly reflects model performance difference.

🔧 Debug
advanced
2:00remaining
Why does this data scaling code cause poor model results?

Consider this Python snippet for scaling features before training:

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.fit_transform(X_test)

Why might this cause poor model performance?

ABecause the scaler is fit separately on test data, causing data leakage and inconsistent scaling.
BBecause StandardScaler cannot be used on numeric data.
CBecause scaling is not needed before training models.
DBecause fit_transform should be replaced with transform on training data.
Attempts:
2 left
💡 Hint

Think about how scaling should be applied to training and test sets.

❓ Model Choice
expert
2:00remaining
Choosing the best approach to handle missing data in a large dataset

You have a large dataset with 30% missing values scattered randomly. Which approach is best to prepare data for a machine learning model?

ARemove all rows with missing values to keep only complete data.
BFill missing values with the mean or median of each feature before training.
CUse a model that can handle missing values natively without imputation.
DReplace missing values with zeros regardless of feature meaning.
Attempts:
2 left
💡 Hint

Consider balancing data loss and preserving information.

Practice

(1/5)
1. Why does data preparation usually take the most time in a machine learning project?
easy
A. Because testing the model takes a long time
B. Because training the model requires many calculations
C. Because raw data is often messy and needs cleaning before use
D. Because deploying the model to production is complex

Solution

  1. Step 1: Understand the nature of raw data

    Raw data collected from real sources often contains errors, missing values, and inconsistencies.
  2. Step 2: Recognize the need for cleaning and organizing

    Before training, data must be cleaned and formatted properly to ensure the model learns correctly.
  3. Final Answer:

    Because raw data is often messy and needs cleaning before use -> Option C
  4. Quick Check:

    Messy data = More preparation time [OK]
Hint: Messy raw data means more cleaning time [OK]
Common Mistakes:
  • Confusing model training time with data cleaning time
  • Thinking deployment takes the most time
  • Assuming testing is the longest step
2. Which of the following is the correct Python code snippet to check for missing values in a pandas DataFrame named df?
easy
A. df.isnull().sum()
B. df.missing_values()
C. df.check_na()
D. df.nulls_count()

Solution

  1. Step 1: Recall pandas method for missing values

    The method isnull() returns a DataFrame of booleans indicating missing values.
  2. Step 2: Summing missing values per column

    Using sum() on the boolean DataFrame counts missing values per column.
  3. Final Answer:

    df.isnull().sum() -> Option A
  4. Quick Check:

    pandas isnull + sum = count missing [OK]
Hint: Use df.isnull().sum() to count missing data [OK]
Common Mistakes:
  • Using non-existent pandas methods
  • Confusing isnull() with isna() (both work but only isnull() shown)
  • Trying to call methods that don't exist on DataFrame
3. Consider this Python code for data preparation:
import pandas as pd

data = {'age': [25, None, 30], 'salary': [50000, 60000, None]}
df = pd.DataFrame(data)
df_filled = df.fillna(df.mean())
print(df_filled)
What will be the output?
medium
A. DataFrame with missing values replaced by zeros
B. DataFrame unchanged with null values still present
C. Error because df.mean() cannot be used with fillna
D. DataFrame with missing values replaced by column means

Solution

  1. Step 1: Understand df.mean()

    Calculates mean of each numeric column ignoring null (NaN) values.
  2. Step 2: fillna with means

    fillna replaces missing values with the corresponding column mean.
  3. Final Answer:

    DataFrame with missing values replaced by column means -> Option D
  4. Quick Check:

    fillna(df.mean()) fills missing with mean [OK]
Hint: fillna(df.mean()) replaces missing with average [OK]
Common Mistakes:
  • Thinking fillna(df.mean()) causes error
  • Assuming missing values remain unchanged
  • Believing missing values become zero
4. You have this code snippet to drop rows with missing values:
import pandas as pd
data = {'height': [170, None, 160], 'weight': [70, 65, None]}
df = pd.DataFrame(data)
df_clean = df.dropna(axis=1)
print(df_clean)
What is wrong with this code if the goal is to remove rows with missing data?
medium
A. dropna() requires a threshold parameter to work
B. dropna(axis=1) removes columns, not rows
C. dropna() cannot be used on DataFrames
D. dropna(axis=1) removes rows, not columns

Solution

  1. Step 1: Understand dropna axis parameter

    axis=0 drops rows; axis=1 drops columns with missing values.
  2. Step 2: Identify the mistake

    Using axis=1 removes columns, but the goal is to remove rows.
  3. Final Answer:

    dropna(axis=1) removes columns, not rows -> Option B
  4. Quick Check:

    axis=1 means columns, not rows [OK]
Hint: Use dropna(axis=0) to remove rows with missing data [OK]
Common Mistakes:
  • Confusing axis=1 with rows
  • Thinking dropna always removes rows by default
  • Believing dropna needs threshold parameter
5. You have a dataset with many missing values and inconsistent formats. Which two data preparation steps combined will most improve model quality and reduce errors?
hard
A. Filling missing values with mean and converting all text to lowercase
B. Randomly shuffling data and dropping duplicate rows
C. Ignoring missing values and training the model directly
D. Removing all rows with any missing data and normalizing numeric columns

Solution

  1. Step 1: Consider filling missing values

    Replacing missing data with mean keeps data size and reduces bias from dropping rows.
  2. Step 2: Standardize text format

    Converting text to lowercase fixes inconsistencies and helps model learn better.
  3. Final Answer:

    Filling missing values with mean and converting all text to lowercase -> Option A
  4. Quick Check:

    Fill missing + text clean = better data [OK]
Hint: Fill missing + clean text improves data quality [OK]
Common Mistakes:
  • Dropping all rows loses too much data
  • Ignoring missing values causes errors
  • Shuffling or dropping duplicates alone won't fix missing data
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard