0
0
ML Pythonml~10 mins

Creating interaction features in ML Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new feature by multiplying two existing features.

ML Python
df['interaction'] = df['feature1'] [1] df['feature2']
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
Using division which may cause errors if denominator is zero.
2fill in blank
medium

Complete the code to create interaction features for all pairs of columns in the DataFrame.

ML Python
from itertools import combinations

for col1, col2 in combinations(df.columns, 2):
    df[f'{col1}_x_{col2}'] = df[col1] [1] df[col2]
Drag options to blanks, or click blank then click option'
A+
B*
C/
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition which does not capture interaction.
Using division which can cause errors.
3fill in blank
hard

Fix the error in the code to correctly create an interaction feature between 'age' and 'income'.

ML Python
df['age_income_interaction'] = df['age'] [1] df['income']
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
Using division which may cause errors.
4fill in blank
hard

Fill both blanks to create a dictionary of interaction features for words longer than 3 characters.

ML Python
interaction_dict = {word: len(word) [1] 2 for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
A**
B%
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using modulus '%' instead of power '**'.
Using '<' instead of '>' for filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary of interaction features where keys are uppercase words and values are their lengths if length is greater than 4.

ML Python
interaction_features = [1]: [2] for word in words if len(word) [3] 4}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for filtering.
Using word instead of word.upper() for keys.