Code QuizIntermediate Encoding an Ordinal Feature
Find why LabelEncoder produces the wrong order for education levels.
Codepython
from sklearn.preprocessing import LabelEncoder
levels = ['high_school', 'bachelor', 'master', 'phd']
encoder = LabelEncoder()
codes = encoder.fit_transform(levels)
# Expecting: high_school=0, bachelor=1, master=2, phd=3
print(codes)
What is the bug in this ordinal encoding attempt?