0
0
ML Pythonml~20 mins

Creating interaction features in ML Python - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interaction Features Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why create interaction features in a model?

Imagine you have two features: hours studied and hours slept. Why might creating an interaction feature (like multiplying these two) help your model?

ABecause the combined effect of studying and sleeping might influence the outcome differently than each alone
BBecause interaction features always reduce the number of features and simplify the model
CBecause multiplying features always fixes missing data problems
DBecause interaction features remove the need for normalization
Attempts:
2 left
💡 Hint

Think about how two things working together might have a different effect than each separately.

Predict Output
intermediate
1:30remaining
Output of interaction feature creation code

What is the output of this Python code that creates an interaction feature?

ML Python
import pandas as pd

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df['A_B'] = df['A'] * df['B']
print(df['A_B'].tolist())
A[1, 2, 3]
B[5, 7, 9]
C[4, 10, 18]
D[4, 5, 6]
Attempts:
2 left
💡 Hint

Multiply each element of column A by the corresponding element in column B.

Model Choice
advanced
2:00remaining
Best model type for interaction features

You have created many interaction features from your dataset. Which model type is best suited to automatically capture complex interactions without explicitly creating interaction features?

AK-Nearest Neighbors without feature scaling
BLinear Regression without interaction terms
CSimple Logistic Regression without polynomial features
DDecision Trees or Random Forests
Attempts:
2 left
💡 Hint

Think about models that split data based on feature values and can capture combinations naturally.

Hyperparameter
advanced
1:30remaining
Hyperparameter affecting interaction feature complexity

When using polynomial features to create interaction terms, which hyperparameter controls the maximum degree of interactions included?

Adegree
Balpha
Cmax_depth
Dlearning_rate
Attempts:
2 left
💡 Hint

It controls how many features are multiplied together.

Metrics
expert
2:00remaining
Effect of interaction features on model metrics

You add interaction features to a regression model. After training, the training error decreases but the validation error increases. What does this indicate?

AThe model is underfitting and needs more features
BThe model is overfitting due to too many interaction features
CThe interaction features improved generalization
DThe data has no noise and the model is perfect
Attempts:
2 left
💡 Hint

Think about what it means when training error goes down but validation error goes up.