Mean target encoding converts a high-cardinality categorical feature into numeric values that summarize the target associated with each category. It is useful when IDs, zip codes, product names, or geographical names would create too many one-hot features for practical modeling. section 2.2.5 section 6.1.3
For regression, each category receives its average target value. For classification, it receives a conditional probability or odds ratio. Because rare categories can overfit, smoothing blends the category estimate with the overall training-set target average. section 6.1.3 section 6.1.3
A practical workflow is:
- Identify categorical features whose cardinality is too large for convenient one-hot encoding; no fixed threshold applies across datasets. section 6.1.3
- Apply target encoding to the selected columns while retaining other preprocessing choices for lower-cardinality categories. section 6.0
- Choose a smoothing value above zero to balance category-specific target information against the global target average, then tune it for the dataset. section 6.1.3
- Prefer target encoding especially with gradient boosting; use embeddings instead when a deep-learning approach is the better fit. section 2.2.5
Pipeline application
The category_encoders TargetEncoder accepts selected high-cardinality columns and a smoothing value, and can be combined with XGBoost and cross-validation in a scikit-learn-compatible pipeline. section 6.1.3


