Skip to content
Quantoros

What's the difference between one-hot encoding and label/ordinal encoding, and when would you use each?

Classic MLLevel: IntermediateClassical machine learning

What's the difference between one-hot encoding and label/ordinal encoding, and when would you use each?

Hints
  • State the task, inputs and prediction target.
  • Compare with a simple baseline: assumptions, objective and independent validation.

Answer

One-hot encoding creates a binary column per category — appropriate for nominal (unordered) categorical variables, since it avoids implying a false ordinal relationship, but it increases dimensionality significantly with high-cardinality features. Label/ordinal encoding maps categories to integers — appropriate for ordinal variables where order is meaningful (e.g., "low/medium/high"), or for tree-based models which can handle arbitrary integer encodings reasonably well without implying a linear relationship the way linear models would.

Source and licence: Ishan Dutta — Awesome Data Science Interview Q&A · MIT

Related questions