Ordinal vs nominal encoding — how do you choose?
easyAnswer
- Ordinal encoding maps categories to integers (0, 1, 2, ...) — makes sense only for ordered categories (education level, star rating), or when passing to a tree-based model that will find splits regardless of numeric order.
- Never use it for unordered categories with a linear/distance model — the integers imply an ordering that doesn't exist.
- One-hot encoding is the safe default for unordered (nominal) categoricals with any model; target encoding for high-cardinality categoricals.
Check yourself — multiple choice
- Always use ordinal encoding for speed
- Ordinal only for ordered categories or tree models; one-hot for unordered with linear/distance models
- Both are always equivalent
- Ordinal encoding is the same as one-hot
Ordinal: only for ordered categories or trees. Otherwise one-hot / target encoding.
#encoding#features#feature-engineering
Practise Supervised Learning
215 interview questions in this topic.
Related questions
- 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?
- You have a feature with 50,000 unique category values. How do you encode it?
- When should you add interaction features to a linear model?
- How do decision trees handle categorical features?