Demonstration 1 of 1
How much to smooth a target encoding, by how much categories really differ
How much smoothing does a target encoding need, and does the answer change with how strongly categories really differ?
A category's raw mean is noisy when it has few rows, and the noise grows when the model trusts the column. A pseudocount pulls each mean toward the global mean in proportion to how few rows support it. When categories barely differ, strong pulling costs nothing and removes noise; when they differ strongly, strong pulling erases real effects. The best m therefore falls as the true spread rises, and no smoothing at all hurts rare categories most.
Scroll sideways for the whole equation
e_c is the encoding of category c, s_c the sum and n_c the count of its training labels, mu the global mean and m the pseudocount; WoE(c) is the log ratio of the category's share among positives to its share among negatives.
Predict first. With a moderate true spread of 1.0, how does an encoding with no smoothing (m = 0) compare with the Chapter 9 default m = 10 on log loss for new rows?
Choose an example
Scroll sideways for the whole figure
Constructed example: thirty seeded synthetic tasks per setting with Zipf-like category frequencies and a logistic regression, measured by the chapter activity.
Calculated values
- Best pseudocount m
- 10
- Log loss at best m
- 0.580
- Log loss with no smoothing
- 0.619
- Log loss at m = 10
- 0.580
- Weight of evidence
- 0.584
With category spread 1.0, the lowest new-row log loss is 0.580 at m = 10. No smoothing scores 0.619, so 0.619 - 0.580 = 0.039 is what skipping smoothing costs; the Chapter 9 default m = 10 is the best setting here. On rare categories (6.7% of new rows) no smoothing scores 0.695 against 0.621 at m = 10. Weight of evidence at smoothing 0.5 scores 0.584.
Worked steps
- Best pseudocount: m = 10 with log loss 0.580.
- No smoothing: 0.619 - 0.580 = 0.039 worse than the best.
- Default m = 10: 0.580 - 0.580 = 0.000 worse than the best.
- Rare categories: m = 0 gives 0.695, m = 10 gives 0.621; weight of evidence 0.640.
Use the idea
Keep Chapter 9's smoothed mean as the baseline, choose m by validation inside the outer boundary rather than by habit, and judge any richer encoder by whether it beats the best smoothed mean on rows it never saw, with rare categories reported separately.
Where the conclusion applies
Constructed data with normally distributed category effects, a logistic model and cross-fitted columns. Weight of Evidence is the chapter's fit_woe formula with smoothing 0.5. No James-Stein, mixed-model or native-categorical encoder is run, so this does not rank those. When categories barely differ the differences between m values are within about 0.002 log loss and should not be over-read.
Check your understanding: Why does the best pseudocount fall as the true spread of category effects grows, and why does skipping smoothing hurt rare categories most?
Chapter 26 source: section "Which One to Use When".