When is one-hot encoding least appropriate?
- Exam domain
- Data Processing20% of the exam
- Difficulty
- Hard
- In this mock
- 10 questions on this domainPractise this domain
Why the exam asks this
Data Processing (20% of the exam)
Objective in the exam guide: Identify and explain the model types or data sets for which one-hot encoding is or is not appropriate
When one-hot encoding fits is named.
Why C is the answer
For a feature with thousands of distinct values
One-hot encoding high-cardinality features creates many sparse columns, slowing training and risking overfitting. Tree models can often use indexed categories or other encodings instead.
Remember: Avoid one-hot for high cardinality.
How it works
Encoding choice depends on cardinality and model type.
In detail
- High cardinality hurts one-hot.
- Linear models need it for few categories.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. For a linear regression with a few unordered categoriesWrong
That is a good fit.
B. For logistic regression with a handful of regionsWrong
That is a good fit.
C. For a feature with thousands of distinct valuesRight
Avoid one-hot for high cardinality.
D. For any categorical feature with three valuesWrongMost tempting
Three values are fine to one-hot.
Why it tempts: Few values seem trivial, but one-hot is fine there.
Use case
An illustrative scenario, not a real incident.
Illustrative: zip code with 40,000 values is target-encoded instead of one-hot encoded.
See it in different ways
flowchart TD
Q{"How many categories?"}
Q -->|"Few"| A0["One-hot"]
Q -->|"Thousands"| A1["Other encoding or indices for trees"]How to read this chart
- At "How many categories?": if "Few", go to "One-hot"; if "Thousands", go to "Other encoding or indices for trees".
mindmap
root(("Encoding"))
n1["One-hot"]
n2["Linear models"]
n3["Low cardinality"]
n4["Indices"]
n5["Tree models"]
n6["Other"]
n7["High cardinality"]How to read this chart
- The centre is "Encoding".
- "One-hot" covers "Linear models", "Low cardinality".
- "Indices" covers "Tree models".
- "Other" covers "High cardinality".