TargetEncoder replaces each category with a smoothed target-derived statistic. Regression uses the category's average target; classification uses conditional probability or odds ratio. Smoothing blends that category estimate with the overall training-set average, reducing overfitting when categories are rare. section 6.1.3
Use TargetEncoder when categorical features have many distinct values:
- Encode high-cardinality fields such as neighborhood or binned geographic coordinates instead of expanding them into thousands of one-hot columns. section 6.1.3
- Set a smoothing value above zero; choose it experimentally, or consider the James-Stein encoder when stronger variance assumptions are acceptable. section 6.1.3
Geographic categories
Binning latitude and longitude into a 100 × 100 grid and combining the bins creates a coordinates feature with 2,259 distinct values; TargetEncoder can convert this high-cardinality feature into target-informed values.
