1. Home
  2. Data Science
  3. Scikit-learn
  4. What does OneHotEncoder(handle_unknown='ignore') do at…

Added 30 Nov -0001

What does OneHotEncoder(handle_unknown='ignore') do at transform time when it meets a category never seen during fit?

  1. It maps the unseen category to the first known category
  2. It encodes that row as all zeros instead of raising an error Correct answer
  3. It adds a new column for the unseen category automatically
  4. It raises an error, since ignore only downgrades the error to a warning

Correct answer

B. It encodes that row as all zeros instead of raising an error

15 views

MCQSEXAM

Explanation

Unknown category handling matters in production, because live data contains levels the training set never saw. The default handle_unknown='error' raises, while 'ignore' produces an all-zero row, which most linear models read as the reference level. Grouping rare levels before fitting, or using a hashing encoder, avoids the problem entirely.

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