What is target encoding?

Quick Overview

Asks what target encoding is and how it turns a high-cardinality categorical feature into a numeric one. Tests understanding of how the encoding is computed, why it risks target leakage and overfitting on rare categories, and which safeguards keep it honest.

What is target encoding?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

What is target encoding? It comes up when a model has to use a categorical feature with many levels, such as city, merchant or product ID. ```hint Watch the rare levels Think about the encoded value of a category that appears only once or twice in the training data, and which rows' labels went into that value. ``` ### What a Strong Answer Covers - Defines target encoding and how it is computed for regression, binary and multiclass targets. - Explains why it is used for high-cardinality categoricals instead of one-hot encoding. - Explains the leakage and overfitting risk, and why rare categories make it worse. - Describes the standard safeguards: smoothing, out-of-fold encoding, fitting on training data only, and a value for unseen categories. ### Follow-up Questions - How would you choose the smoothing strength? - Leave-one-out encoding excludes each row's own label. Why does it still leak? - How would you target-encode a categorical feature when the data are ordered in time? - When would you choose one-hot encoding, feature hashing or learned embeddings instead?

Overview: Asks what target encoding is and how it turns a high-cardinality categorical feature into a numeric one. Tests understanding of how the encoding is computed, why it risks target leakage and overfitting on rare categories, and which safeguards keep it honest.

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

What is target encoding?

It comes up when a model has to use a categorical feature with many levels, such as city, merchant or product ID.

What a Strong Answer Covers Guidance

  • Defines target encoding and how it is computed for regression, binary and multiclass targets.
  • Explains why it is used for high-cardinality categoricals instead of one-hot encoding.
  • Explains the leakage and overfitting risk, and why rare categories make it worse.
  • Describes the standard safeguards: smoothing, out-of-fold encoding, fitting on training data only, and a value for unseen categories.

Follow-up Questions Guidance

  • How would you choose the smoothing strength?
  • Leave-one-out encoding excludes each row's own label. Why does it still leak?
  • How would you target-encode a categorical feature when the data are ordered in time?
  • When would you choose one-hot encoding, feature hashing or learned embeddings instead?