EasyDeepLearn

You have a feature with 50,000 unique category values. How do you encode it?

medium

Answer

  • One-hot is out — 50k sparse columns kill most models.
  • Options: (1) target encoding (with K-fold + smoothing) for gradient boosting or linear models; (2) frequency encoding to distinguish common vs rare; (3) feature hashing to a fixed-size vector; (4) entity embeddings — a learned dense vector per category, trained with a neural net or via factorization machines; (5) group rare categories into 'Other' below a min-count threshold.
  • Often combine target + frequency encoding.
Check yourself — multiple choice
  • One-hot encode with a sparse matrix
  • Target encoding, frequency, hashing, entity embeddings, or grouping — pick the mix per model
  • Drop the feature
  • One-hot is the only correct answer

Target / frequency / hashing / embeddings / rare-bucket — no single answer, combine as needed.

#encoding#features#feature-engineering

Practise Supervised Learning

215 interview questions in this topic.

Related questions