Skip to content

When is simple target encoding optimal? Moment exactness for sparse categorical features, and the limits of estimating their information

Damián G. Hernández

stat.ML

Abstract

Target encoding replaces each level of a high-cardinality categorical feature by a smoothed estimate of the target rate. We ask how well any encoder can do when most test rows fall on levels seen zero, one or two times, what a simple encoder misses on real data, and whether the information I(X;Y)I(X;Y) the feature carries can be estimated in this regime. The Bayes prediction after nn observations depends only on the first n+1n+1 moments of the prior. Hence, when a level's target rate does not depend on its popularity (exchangeability), a beta prior matched to two moments is exactly the oracle on levels seen at most once, and type-II maximum likelihood recovers it asymptotically when no level is seen more than twice. A moment test rejects exchangeability on 21 of 23 real features. Without it, the oracle prior for levels seen nn times is the law of the target rate among levels seen n+1n+1 times; this shift yields a correction read off the singleton and doubleton counts, and a frequency-aware prior that closes half to four-fifths of the remaining gap on real-data subsampling oracles. Information is harder: from levels seen at most LL times, I(X;Y)I(X;Y) is only partially identified, within a worst-case half-width of 0.038 nats for L=2L=2 and about 0.22/L20.22/L^2 for larger even LL, and without exchangeability only a trivial bound holds for the singletons' share. On 24 real features, fitted priors (beta, NPMLE, GLMM, frequency-aware) differ by less than 0.01 nats per test row; larger losses come from a fixed smoothing strength far from the fitted one, such as the common default m=20m=20, and from predicting a GLMM at its mode. A likelihood-region interval for I(X;Y)I(X;Y) covers in our synthetic studies and on all but one exchangeable real pool; on real features, stratified identified intervals are several hundredths of a nat wide, and up to 0.45 nats on the sparsest.

Create a lesson

Metadata

Categories
stat.ML, cs.LG, physics.data-an, stat.ME
Comments
55 pages