What is target encoding?
Target encoding replaces a categorical value with the average value of the target for that value of the feature.
Target encoding replaces a categorical value with the average value of the target for that value of the feature.
Card 1 of 259. Answer: Target encoding replaces a categorical value with the average value of the target for that value of the feature.
About · Quizzes · History of AI · To suggest new questions or report an error send me a dm.
Target encoding, also called mean encoding, replaces each category with the average target of the training rows in that category: the mean for a regression target, the share of positives for a binary one. A high-cardinality column becomes one numeric column.
Rare categories give noisy means, so they are shrunk toward the global mean: encoding = (n · category_mean + m · global_mean) / (n + m), with n the category's row count and m the strength. With a global rate of 0.10 and m = 20, a city with 3 conversions in 4 rows gets (3 + 2) / 24 ≈ 0.21 instead of 0.75, while one with 2,000 rows at 0.12 stays near 0.12.
Leakage is the usual follow-up. If a row's own label feeds its encoding, a category seen once is encoded as its own answer. Compute encodings out of fold, as scikit-learn's TargetEncoder does in fit_transform, or use CatBoost's ordered target statistics. Daniele Micci-Barreca described the method, with empirical Bayes shrinkage, in 2001.