When would you use target encoding instead of one-hot encoding?

Quick Overview

Asks when to replace one-hot encoding of a categorical feature with target encoding. It tests your judgment about high-cardinality features, how target leakage creeps into encoded features, and how to handle rare and unseen categories.

When would you use target encoding instead of one-hot encoding?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

When would you use target encoding instead of one-hot encoding for a categorical feature? ```hint Count the columns Think about what one-hot encoding does to a feature with tens of thousands of levels, and what a single numeric column would have to carry instead. ``` ```hint Watch the label Ask what happens when a row's own target value goes into the number that encodes its category. ``` ### What a Strong Answer Covers - The cardinality argument, and what target encoding replaces each category with - Leakage from using a row's own target, and out-of-fold encoding as the fix - Smoothing toward the global mean for rare and unseen categories - When one-hot encoding is still the better choice ### Follow-up Questions - How would you target-encode a category in a time-ordered problem, such as fraud scoring on a stream of transactions, without leaking future labels? - How does target encoding compare with the hashing trick or learned embeddings for a feature with millions of levels? - A category's target rate shifts after deployment. What happens to a model that relies on its target encoding, and how would you detect it? - How does CatBoost compute its target statistics so that a row never sees its own label?

Overview: Asks when to replace one-hot encoding of a categorical feature with target encoding. It tests your judgment about high-cardinality features, how target leakage creeps into encoded features, and how to handle rare and unseen categories.

Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

When would you use target encoding instead of one-hot encoding for a categorical feature?

What a Strong Answer Covers Guidance

  • The cardinality argument, and what target encoding replaces each category with
  • Leakage from using a row's own target, and out-of-fold encoding as the fix
  • Smoothing toward the global mean for rare and unseen categories
  • When one-hot encoding is still the better choice

Follow-up Questions Guidance

  • How would you target-encode a category in a time-ordered problem, such as fraud scoring on a stream of transactions, without leaking future labels?
  • How does target encoding compare with the hashing trick or learned embeddings for a feature with millions of levels?
  • A category's target rate shifts after deployment. What happens to a model that relies on its target encoding, and how would you detect it?
  • How does CatBoost compute its target statistics so that a row never sees its own label?