Bird
Raised Fist0
Data Analysis Pythondata~20 mins

Why engineered features improve analysis in Data Analysis Python - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Feature Engineering Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How do engineered features help machine learning models?

Which of the following best explains why engineered features improve the performance of machine learning models?

AThey make the dataset more complex without adding useful information.
BThey reduce the size of the dataset by removing rows.
CThey add new information that helps models find patterns more easily.
DThey always increase the number of features without improving accuracy.
Attempts:
2 left
💡 Hint

Think about how new features can help models understand data better.

❓ data_output
intermediate
2:00remaining
Output of feature scaling on data

Given the following code that scales a feature using min-max scaling, what is the output?

Data Analysis Python
import pandas as pd
from sklearn.preprocessing import MinMaxScaler

data = pd.DataFrame({'age': [20, 30, 40, 50]})
scaler = MinMaxScaler()
data['age_scaled'] = scaler.fit_transform(data[['age']])
print(data)
ARaises a TypeError due to wrong input format
B{'age': [20, 30, 40, 50], 'age_scaled': [20, 30, 40, 50]}
C{'age': [20, 30, 40, 50], 'age_scaled': [1.0, 0.6667, 0.3333, 0.0]}
D{'age': [20, 30, 40, 50], 'age_scaled': [0.0, 0.3333, 0.6667, 1.0]}
Attempts:
2 left
💡 Hint

Min-max scaling transforms values to a 0-1 range based on min and max.

❓ visualization
advanced
3:00remaining
Effect of polynomial features on data separation

Which plot best shows how adding polynomial features can help separate data that is not linearly separable?

Data Analysis Python
import matplotlib.pyplot as plt
import numpy as np
from sklearn.preprocessing import PolynomialFeatures

np.random.seed(0)
X = np.random.randn(100, 1)
y = (X[:, 0] > 0).astype(int)
poly = PolynomialFeatures(degree=2, include_bias=False)
X_poly = poly.fit_transform(X)

plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
plt.scatter(X, y, c=y, cmap='bwr')
plt.title('Original Feature')
plt.xlabel('X')
plt.ylabel('Class')

plt.subplot(1, 2, 2)
plt.scatter(X_poly[:, 0], X_poly[:, 1], c=y, cmap='bwr')
plt.title('With Polynomial Feature')
plt.xlabel('X')
plt.ylabel('X squared')
plt.tight_layout()
plt.show()
ABoth plots show perfect linear separation of classes.
BLeft plot shows overlapping classes; right plot shows classes separated by curve.
CRight plot shows classes mixed more than left plot.
DLeft plot shows classes separated; right plot shows overlapping classes.
Attempts:
2 left
💡 Hint

Polynomial features add curves that can separate data better than a straight line.

🔧 Debug
advanced
2:00remaining
Identify the error in feature extraction code

What error will this code raise when trying to create a new feature 'bmi_category' based on 'bmi' values?

import pandas as pd
data = pd.DataFrame({'bmi': [18, 22, 27, 31]})
def bmi_cat(bmi):
    if bmi < 18.5:
        return 'Underweight'
    elif bmi < 25:
        return 'Normal'
    elif bmi < 30:
        return 'Overweight'
    else:
        return 'Obese'
data['bmi_category'] = data['bmi'].apply(bmi_cat)
ASyntaxError due to missing colon after else
BTypeError because 'bmi' is not a number
CKeyError because 'bmi_category' column does not exist
DNo error; code runs correctly
Attempts:
2 left
💡 Hint

Check the syntax of the if-else statements carefully.

🚀 Application
expert
3:00remaining
Choosing engineered features for time series forecasting

You have daily sales data and want to improve forecasting by adding engineered features. Which feature is most likely to improve the model?

ADay of the week encoded as a number from 0 (Monday) to 6 (Sunday)
BRandom numbers generated for each day to add noise
CCustomer names as text strings
DUnique ID numbers for each sale
Attempts:
2 left
💡 Hint

Think about what patterns repeat regularly in daily sales.

Practice

(1/5)
1. Why do engineered features often improve data analysis results?
easy
A. They highlight important patterns not obvious in raw data
B. They reduce the size of the dataset by removing rows
C. They always increase the number of features without filtering
D. They replace the need for any data cleaning

Solution

  1. Step 1: Understand the role of engineered features

    Engineered features transform raw data into forms that better reveal patterns.
  2. Step 2: Compare with other options

    Options B, C, and D describe unrelated or incorrect effects of engineered features.
  3. Final Answer:

    They highlight important patterns not obvious in raw data -> Option A
  4. Quick Check:

    Engineered features = highlight patterns [OK]
Hint: Engineered features reveal hidden patterns in data [OK]
Common Mistakes:
  • Thinking engineered features reduce dataset size
  • Assuming engineered features always add more features
  • Believing engineered features replace data cleaning
2. Which of the following is the correct way to create a new feature age_group from age in pandas using a condition?
easy
A. df['age_group'] = df['age'].filter(lambda x: 'adult' if x >= 18 else 'child')
B. df['age_group'] = df['age'].map('adult' if df['age'] >= 18 else 'child')
C. df['age_group'] = df['age'].apply(lambda x: 'adult' if x >= 18 else 'child')
D. df['age_group'] = df['age'].groupby(lambda x: 'adult' if x >= 18 else 'child')

Solution

  1. Step 1: Identify correct pandas method for conditional feature creation

    The apply method with a lambda function correctly applies a condition to each value.
  2. Step 2: Check other options for errors

    map expects a mapping dict or function, filter is for filtering rows, groupby is for grouping data, so they are incorrect here.
  3. Final Answer:

    df['age_group'] = df['age'].apply(lambda x: 'adult' if x >= 18 else 'child') -> Option C
  4. Quick Check:

    Use apply with lambda for conditional feature [OK]
Hint: Use apply with lambda for conditional new features [OK]
Common Mistakes:
  • Using map with a conditional expression incorrectly
  • Confusing filter with apply for feature creation
  • Using groupby instead of apply for new column
3. Given the code below, what will be the output of print(df)?
import pandas as pd
df = pd.DataFrame({'height_cm': [170, 160, 180], 'weight_kg': [70, 60, 80]})
df['bmi'] = df['weight_kg'] / (df['height_cm'] / 100) ** 2
print(df)
medium
A. SyntaxError due to incorrect operator precedence
B. {'height_cm': [170, 160, 180], 'weight_kg': [70, 60, 80], 'bmi': [24.22, 23.44, 24.69]}
C. DataFrame with bmi column calculated as weight_kg multiplied by height_cm
D. DataFrame with bmi column calculated as weight_kg divided by height_cm squared in meters

Solution

  1. Step 1: Understand the BMI calculation in code

    BMI is weight in kg divided by height in meters squared. The code correctly converts height_cm to meters and squares it.
  2. Step 2: Check output format

    The print shows a DataFrame with a new 'bmi' column calculated as described, not a dictionary or error.
  3. Final Answer:

    DataFrame with bmi column calculated as weight_kg divided by height_cm squared in meters -> Option D
  4. Quick Check:

    BMI = weight / (height/100)^2 [OK]
Hint: Check formula carefully for correct calculation [OK]
Common Mistakes:
  • Confusing multiplication with division in BMI formula
  • Expecting dictionary output instead of DataFrame
  • Thinking code causes syntax error
4. The following code tries to create a new feature income_level but raises an error. What is the error and how to fix it?
df['income_level'] = df['income'].apply(lambda x: 'high' if x > 50000 else 'low' if x <= 50000)
medium
A. No error; code runs fine
B. SyntaxError due to missing else clause; fix by adding final else
C. KeyError because 'income' column does not exist
D. TypeError because apply cannot use lambda functions

Solution

  1. Step 1: Identify the lambda function structure

    The lambda uses nested if-else but misses a final else clause, causing SyntaxError.
  2. Step 2: Fix the lambda expression

    Add a final else clause to cover all cases, e.g., lambda x: 'high' if x > 50000 else 'low'.
  3. Final Answer:

    SyntaxError due to missing else clause; fix by adding final else -> Option B
  4. Quick Check:

    Lambda if-else must cover all cases [OK]
Hint: Ensure lambda if-else has final else clause [OK]
Common Mistakes:
  • Assuming apply cannot use lambda
  • Ignoring missing else causing syntax error
  • Thinking income column is missing without checking
5. You have a dataset with columns temperature_c and humidity. You want to create a new feature heat_index that combines both to better predict discomfort. Which approach best explains why engineered features like heat_index improve analysis?
hard
A. Combining temperature and humidity into heat_index captures interaction effects raw features miss
B. Using only temperature or humidity separately is always better for simplicity
C. Heat_index replaces raw data so original features are no longer needed
D. Engineered features like heat_index reduce dataset size by removing columns

Solution

  1. Step 1: Understand interaction effects in features

    Heat index combines temperature and humidity to capture how they jointly affect discomfort, which single features miss.
  2. Step 2: Evaluate other options

    Options A, C, and D misunderstand feature engineering benefits or effects on data.
  3. Final Answer:

    Combining temperature and humidity into heat_index captures interaction effects raw features miss -> Option A
  4. Quick Check:

    Engineered features = capture interactions [OK]
Hint: Engineered features capture combined effects of raw data [OK]
Common Mistakes:
  • Thinking single features are always better
  • Believing engineered features replace raw data completely
  • Assuming engineered features reduce dataset size
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