When should OneHotEncoder be preferred to LabelEncoder for a categorical feature?
Correct answer
B. Whenever the categories have no natural order
18 views
B. Whenever the categories have no natural order
18 views
OneHotEncoder creates a separate binary column per category, so a linear model does not read an arbitrary code such as 2 as twice 1. LabelEncoder maps categories to integers and is meant mainly for the target vector, not for nominal features. Tree-based models can cope with integer codes, but one-hot encoding remains the safer default for anything the model treats as numeric magnitude.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.