← Back to Classic ML Mind Map
⚡Flashcard Drill➔
📊 Classic MLID: target-encoding

Target Encoding

目标编码 Target Encoding
🎯Core Definition
Target encoding encodes high-cardinality categorical features (user_id, city, item ID) with the mean target per category. Smoothing formula: TE=λ(ni)⋅mean(yi)+(1−λ(ni))⋅global_meanTE = \lambda(n_i) \cdot \text{mean}(y_i) + (1 - \lambda(n_i)) \cdot \text{global\_mean}, where the confidence weight is λ(ni)=nini+m\lambda(n_i) = \frac{n_i}{n_i + m} — the larger the category count nin_i, the more the within-category mean is trusted, and the smoothing strength mm controls how hard the estimate shrinks toward the global mean, protecting small groups from noisy means. Leakage risk: computing group means on the full dataset makes both train and validation features carry target information (inflated CV, production collapse) — the biggest trap of TE. Fixes: out-of-fold (OOF) encoding — for each sample, compute the mean from the folds that did not contain it; CatBoost goes further with Ordered Target Statistics — compute statistics using only history samples preceding the current one, structurally eliminating leakage.
💡Use Cases
high-cardinality categorical features with tree models (GBDT/LightGBM) and Kaggle competitions; interviews ask “why not one-hot”, “how to prevent TE leakage”, “how to choose m”.
⚡Key Problems Solved
one-hot explodes dimensionality for high cardinality (1M user_ids become 1M columns, memory and sparsity disaster); raw group-mean encoding leaks the target and overfits small groups; smoothing shrinkage plus OOF/Ordered encoding keeps the category-target association while controlling leakage and overfitting — CatBoost replaces one-hot with Ordered encoding precisely so categorical features can join training directly.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Target Encoding.
Use Cases
In production engineering, what are the primary use cases for Target Encoding and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Write the smoothed TE formula TE=λ⋅mean(yi)+(1−λ)⋅globalTE = \lambda \cdot \text{mean}(y_i) + (1-\lambda) \cdot \text{global} with λ(ni)=nini+m\lambda(n_i) = \frac{n_i}{n_i+m}; intuitively, what do m and nin_i do?
2
Why does full-data group-mean encoding leak? Trace the leakage path and the mechanism of inflated CV scores?
3
Concrete steps of OOF (out-of-fold) encoding? How does it differ from CatBoost's Ordered Target Statistics?
4
Why target encoding instead of one-hot for high-cardinality features? Compare dimensionality, sparsity and information content?
5
How to choose the smoothing m? What happens to small groups without shrinkage (high encoding variance, overfitting)?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Target Encoding"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
← Previous CardHuber Loss & Focal LossNext Card →Data Leakage

🔗 More Classic ML Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/ML/card/target-encoding