Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the LabelEncoder class from sklearn.
ML Python
from sklearn.preprocessing import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a scaler class instead of LabelEncoder.
Using OneHotEncoder which is for a different encoding.
✗ Incorrect
LabelEncoder is the class used to convert categorical labels into numeric form.
2fill in blank
mediumComplete the code to create a LabelEncoder object named 'le'.
ML Python
le = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Creating an instance of a scaler instead of LabelEncoder.
Using OneHotEncoder which is not for label encoding.
✗ Incorrect
LabelEncoder() creates an instance to encode labels.
3fill in blank
hardFix the error in the code to fit and transform the labels list using LabelEncoder.
ML Python
labels = ['cat', 'dog', 'cat', 'bird'] encoded = le.[1](labels)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only fit which does not transform the data.
Using transform before fitting causes an error.
Using a non-existent method 'encode'.
✗ Incorrect
fit_transform fits the encoder and transforms the labels in one step.
4fill in blank
hardFill both blanks to create a dictionary mapping original labels to encoded values.
ML Python
mapping = {label: encoded[1] for [2], label in enumerate(labels)} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation to index a list.
Using curly braces instead of parentheses for unpacking.
✗ Incorrect
Use square brackets to index the encoded list and parentheses to unpack enumerate.
5fill in blank
hardFill all three blanks to inverse transform encoded labels back to original labels.
ML Python
original = le.[1]([encoded[2]]) print(list([3]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of inverse_transform.
Using parentheses instead of square brackets for indexing.
Printing the wrong variable.
✗ Incorrect
inverse_transform converts encoded labels back; use [0] to get first element if needed; print the original list.