mlprep
Medium12 min·1 round·Feature Engineering

How do you encode categorical features? Compare one-hot, target encoding, and embeddings.

Written by the mlprep team · Updated

Interviewer Mode
Interviewer

You have a categorical feature with high cardinality — say, 10,000 unique zip codes. How do you encode it? Walk me through the trade-offs of different approaches.

Ready to compare your reasoning?

The key takeaway unlocks after you reveal an expert answer.

Follow-up Questions to Test Yourself

Interviewers often pivot here once you cover the core concept.

  • How would you implement out-of-fold target encoding correctly in a sklearn pipeline without leakage?
  • Your model is deployed. A new product category appears in production that wasn't in training. How do you handle it?
  • How do entity embeddings (like those used in FastAI's tabular model) compare to standard target encoding on structured data?

How confident do you feel explaining this?

Track your understanding or flag it to revisit before your next loop.

Related Questions