Skip to main content

Module target_encoder

Module target_encoder 

Source
Expand description

Target encoder: encode categorical features using target statistics.

TargetEncoder replaces each category with the mean of the target variable for that category, regularised toward the global mean using smoothing.

This is especially useful for high-cardinality categorical features where one-hot encoding would produce too many columns.

§Smoothing

The encoded value for category c is:

encoded(c) = (count(c) * mean_c + smooth * global_mean) / (count(c) + smooth)

where smooth controls the degree of regularisation.

Structs§

FittedTargetEncoder
A fitted target encoder holding per-feature, per-category encoding values.
TargetEncoder
An unfitted target encoder.