Why does one-hot encoding fail when applied to high-cardinality categorical features?

Quick Overview

Explain why one-hot encoding breaks down for categorical features with thousands of levels, such as zip codes or product IDs. Tests understanding of dimensionality, sparse low-support columns, tree splits, unseen categories in production, and the alternative encodings used in practice.

Why does one-hot encoding fail when applied to high-cardinality categorical features?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

Why does one-hot encoding fail when applied to high-cardinality categorical features? Think of a feature such as zip code, product ID or merchant name, with thousands of distinct values. ```hint Count two things Count the columns the encoding creates, then count how many training rows have a 1 in a typical column. ``` ### What a Strong Answer Covers - The effect on dimensionality, memory and distance-based models. - Why rare levels get unreliable weights or splits, and what that means for overfitting. - How one-hot columns interact with tree splits, feature subsampling and feature importance. - The lack of shared information between related categories, and what happens with categories unseen in training. - At least two alternatives, with a note on when each one fits. ### Follow-up Questions - How does out-of-fold target encoding avoid leakage, and what smoothing would you add for rare categories? - What do hash collisions cost, and how would you choose the number of hash buckets? - When is one-hot encoding of a high-cardinality feature still a reasonable choice? - How would you handle a category that first appears after the model is deployed?

Overview: Explain why one-hot encoding breaks down for categorical features with thousands of levels, such as zip codes or product IDs. Tests understanding of dimensionality, sparse low-support columns, tree splits, unseen categories in production, and the alternative encodings used in practice.

General logo
General
Nov 24, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

Why does one-hot encoding fail when applied to high-cardinality categorical features?

Think of a feature such as zip code, product ID or merchant name, with thousands of distinct values.

What a Strong Answer Covers Guidance

  • The effect on dimensionality, memory and distance-based models.
  • Why rare levels get unreliable weights or splits, and what that means for overfitting.
  • How one-hot columns interact with tree splits, feature subsampling and feature importance.
  • The lack of shared information between related categories, and what happens with categories unseen in training.
  • At least two alternatives, with a note on when each one fits.

Follow-up Questions Guidance

  • How does out-of-fold target encoding avoid leakage, and what smoothing would you add for rare categories?
  • What do hash collisions cost, and how would you choose the number of hash buckets?
  • When is one-hot encoding of a high-cardinality feature still a reasonable choice?
  • How would you handle a category that first appears after the model is deployed?