Back to ML Engineer Mind Map
中文·English
💻 ML EngineerID: mle-oof-target-encoding

OOF Target Encoding & Anti-Leakage

OOF 目标编码与防目标穿越机制
🎯Core Definition
Out-of-Fold (OOF) Target Encoding is the gold-standard dense representation method for high-cardinality categorical features (ZIP codes, merchant IDs, device models with 104+10^4+ categories) engineered with strict anti-leakage invariants; standard Target Encoding replaces categorical levels with smoothed conditional expectations: x^i=λ(n)yˉc+(1λ(n))yˉglobal\hat{x}_i = \lambda(n) \bar{y}_c + (1 - \lambda(n)) \bar{y}_{\text{global}} (where λ(n)\lambda(n) is a Bayesian shrinkage weighting factor based on class count nn); to prevent catastrophic target leakage, OOF splits training data into KK folds: target encodings for Fold kk are computed exclusively from the remaining K1K-1 folds; test sets are mapped using global smoothed means from the full training set.
💡Use Cases
High-cardinality feature compression in tabular ML, ad ranking CTR merchant features, and Kaggle competitive modeling.
Key Problems Solved
One-Hot encoding blows up dimensionality and memory; naive target encoding memorizes target labels directly into features causing massive over-fitting; OOF guarantees leak-free, high-signal continuous features.
🎯5 High-Frequency Exam Points
1
Write the complete Pure Numpy/Pandas implementation of 5-fold OOF Target Encoding with Bayesian smoothing?
2
Mathematically explain why naive target encoding causes target leakage by contaminating feature values with the row's own label?
3
Explain how CatBoost's Ordered Target Encoding calculates cumulative online historical statistics to eliminate leakage naturally?
4
How does adding Gaussian noise/jittering to target-encoded features regularize trees against memorizing rare categories?
5
How should target-encoded transformers handle unseen categorical levels during online inference using global prior baselines?
🔗Foundational Prerequisite Cards (Click to Review)
Updated 2026-08-14
🎯
Test Your Knowledge: Practice Questions for "OOF Target Encoding & Anti-Leakage"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardMissing Value Imputation & MICENext CardFeature Selection, Permutation & SHAP

🔗 More ML Engineer Knowledge Cards

Bias-Variance Tradeoff & OverfittingLoss Function Taxonomy & GradientsOptimizer Convergence & MomentumEnsemble Stacking & Blending