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+ 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 (where
λ(n) is a Bayesian shrinkage weighting factor based on class count
n); to prevent catastrophic target leakage, OOF splits training data into
K folds: target encodings for Fold
k are computed exclusively from the remaining
K−1 folds; test sets are mapped using global smoothed means from the full training set.