Why is naive target encoding susceptible to severe overfitting?

Quick Overview

Asks why naive target encoding of categorical features overfits so badly. It tests whether you understand label leakage, the noise in rare categories, the gap between training and inference, and how to encode categories safely.

Why is naive target encoding susceptible to severe overfitting?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Target encoding replaces each level of a categorical feature with the mean of the target for that level. Why is the naive version, which computes those means on the same rows the model trains on, susceptible to severe overfitting? ```hint Follow one row's label Pick a single training row and ask whether its own label went into the number that now sits in its feature column. Then consider what happens to that number when the category has only one or two rows. ``` ### What a Strong Answer Covers - The self-leakage mechanism, including the extreme case of a one-row category - Why rare levels produce noisy values that look confident - The mismatch between the feature's behavior at training time and at inference, and the symptoms it produces - Concrete fixes and what each one addresses ### Follow-up Questions - Why does leave-one-out target encoding still leak, and how does K-fold encoding avoid it? - How would you choose the smoothing strength? - How do you encode a category that appears at inference but never appeared in training?

Overview: Asks why naive target encoding of categorical features overfits so badly. It tests whether you understand label leakage, the noise in rare categories, the gap between training and inference, and how to encode categories safely.

General logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

Target encoding replaces each level of a categorical feature with the mean of the target for that level. Why is the naive version, which computes those means on the same rows the model trains on, susceptible to severe overfitting?

What a Strong Answer Covers Guidance

  • The self-leakage mechanism, including the extreme case of a one-row category
  • Why rare levels produce noisy values that look confident
  • The mismatch between the feature's behavior at training time and at inference, and the symptoms it produces
  • Concrete fixes and what each one addresses

Follow-up Questions Guidance

  • Why does leave-one-out target encoding still leak, and how does K-fold encoding avoid it?
  • How would you choose the smoothing strength?
  • How do you encode a category that appears at inference but never appeared in training?