1. Home
  2. Data Science
  3. Scikit-learn
  4. When should OneHotEncoder be preferred to LabelEncoder for…

Added 30 Nov -0001

When should OneHotEncoder be preferred to LabelEncoder for a categorical feature?

  1. Whenever the model is a decision tree
  2. Whenever the categories have no natural order Correct answer
  3. Whenever the categories are numeric identifiers
  4. Whenever the column contains missing values

Correct answer

B. Whenever the categories have no natural order

18 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Scikit-learn MCQs

Practise all Scikit-learn MCQs

Similar MCQs