Skip to main content

Module encode

Module encode 

Source
Expand description

Out-of-fold target encoding of a high-cardinality factor with credibility (Holmes and Casotto, CAS Monograph 16, chapter 6).

Each level’s encoding is its actual-to-expected ratio shrunk to 1 by the credibility z = n / (n + K), with n the level’s exposure: z A / E + (1 − z). The expected values come from the caller (the overall mean times exposure, or a first model’s predictions), so the ratio measures what that model misses. On the training rows each row is encoded from the other folds only, so a row’s own response never enters its encoding; new data is encoded from all the training rows.

Structs§

TargetEncoding
The encoding of each level learned from all the training rows, from target_encode; encode applies it to new data.

Functions§

target_encode
The out-of-fold encoding of each training row, and the encoding from all the rows for new data.