Target encoding replaces a category with the average label for that category. Done naively on the training set, each sample's own label leaks into its feature and the model overfits. CatBoost (Prokhorenkova et al., 2018) avoids this by encoding each sample using only the samples that came before it.
Implement ordered_target_encoding(cats, ys, prior, a), which encodes each sample from earlier samples in its category, blended with the prior.
Keep a running sum and count per category. Encode the current sample first, then update the sums with its label.
No results yet
Run your code to check it against the examples, or submit to run every test.