Challenge - 5 Problems
Interaction Features Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of interaction feature multiplication
What is the output DataFrame after creating an interaction feature by multiplying columns 'A' and 'B'?
Data Analysis 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)
Attempts:
2 left
💡 Hint
Multiply each value in column 'A' by the corresponding value in column 'B'.
✗ Incorrect
The interaction feature 'A_B' is created by multiplying each element of 'A' with the corresponding element of 'B'. So 1*4=4, 2*5=10, 3*6=18.
❓ data_output
intermediate1:30remaining
Number of unique interaction features created
Given a DataFrame with columns 'X', 'Y', and 'Z', how many unique pairwise interaction features can be created by multiplying two different columns?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'X': [1,2], 'Y': [3,4], 'Z': [5,6]}) # Interaction features are created by multiplying pairs of different columns pairs = [(a,b) for i,a in enumerate(df.columns) for b in df.columns[i+1:]] print(len(pairs))
Attempts:
2 left
💡 Hint
Count all unique pairs without repetition or order.
✗ Incorrect
With 3 columns, the number of unique pairs is 3 choose 2 = 3. The pairs are (X,Y), (X,Z), and (Y,Z).
🔧 Debug
advanced2:00remaining
Identify the error in interaction feature creation
What error will this code raise when trying to create an interaction feature by multiplying columns 'A' and 'B'?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': ['4', '5', '6']}) df['A_B'] = df['A'] * df['B']
Attempts:
2 left
💡 Hint
Check the data types of columns before multiplication.
✗ Incorrect
Column 'B' contains strings, so multiplying an int by a str raises a TypeError about unsupported operand types.
🚀 Application
advanced2:30remaining
Creating polynomial interaction features with scikit-learn
Which code snippet correctly creates interaction features (degree 2) from a numeric DataFrame using scikit-learn's PolynomialFeatures?
Data Analysis Python
import pandas as pd from sklearn.preprocessing import PolynomialFeatures df = pd.DataFrame({'X': [1, 2], 'Y': [3, 4]}) poly = PolynomialFeatures(degree=2, interaction_only=True, include_bias=False) X_poly = poly.fit_transform(df) print(X_poly)
Attempts:
2 left
💡 Hint
Interaction features exclude powers of single features and bias adds a column of ones.
✗ Incorrect
Setting interaction_only=True creates only interaction terms without powers. include_bias=False excludes the constant term. Degree=2 creates pairwise interactions.
🧠 Conceptual
expert1:30remaining
Effect of interaction features on model complexity
How does adding interaction features between numeric variables affect the complexity of a linear regression model?
Attempts:
2 left
💡 Hint
Think about how adding new features changes the model's ability to fit data.
✗ Incorrect
Adding interaction features increases the number of predictors, allowing the model to capture more complex relationships but also increasing the risk of fitting noise.