You have a feature with 50,000 unique category values. How do you encode it?
mediumAnswer
- 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
- Ordinal vs nominal encoding — how do you choose?
- What is target encoding and when is it useful?
- How do you encode cyclical features like hour-of-day or day-of-week?
- How do you turn text into features for a classical model?
- When should you add interaction features to a linear model?
- How do decision trees handle categorical features?