0
0
ML Pythonml~10 mins

Label encoding in ML Python - Interactive Code Practice

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

Complete 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'
ALabelEncoder
BOneHotEncoder
CStandardScaler
DMinMaxScaler
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a scaler class instead of LabelEncoder.
Using OneHotEncoder which is for a different encoding.
2fill in blank
medium

Complete the code to create a LabelEncoder object named 'le'.

ML Python
le = [1]()
Drag options to blanks, or click blank then click option'
AStandardScaler
BOneHotEncoder
CMinMaxScaler
DLabelEncoder
Attempts:
3 left
💡 Hint
Common Mistakes
Creating an instance of a scaler instead of LabelEncoder.
Using OneHotEncoder which is not for label encoding.
3fill in blank
hard

Fix 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'
Afit_transform
Btransform
Cfit
Dencode
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'.
4fill in blank
hard

Fill 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'
A[]
B()
C{}
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation to index a list.
Using curly braces instead of parentheses for unpacking.
5fill in blank
hard

Fill 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'
Ainverse_transform
B[0]
Coriginal
D(0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of inverse_transform.
Using parentheses instead of square brackets for indexing.
Printing the wrong variable.