Target leakage occurs when target or label information enters features, preprocessing, or training computations in a way unavailable when making predictions. It can make evaluation look better while weakening estimates of generalization. section 8.1.3
Greedy target encoding
Suppose the category red is replaced by the mean target for all red examples in the training data. Reusing that target-derived value to encode both training and test rows lets training labels influence test representations. This is target leakage and can also create prediction shift between the two sets. A hold-out encoding set separates target-statistic computation from ordinary training and testing; leave-one-out encoding instead excludes only the row currently being encoded, saving data but not completely removing prediction shift. section 8.1.3
Figure 8.3 Target leakage from the training to test set illustrated. All the targets (labels) in the training set are greedily used to create an encoding for red, which is used to encode this category in both the training and test sets, leading to target leakage.
Shows how training labels used to encode a category are carried into the test representation. section 8.1.3
Prevent or reduce leakage by applying the following controls:
- Keep the test set completely outside preprocessing, training, and validation; fit preprocessing on training data and only transform the test data afterward. section 8.1.3 section 8.1.4
- Use a hold-out encoding set when target statistics require strong separation, or use leave-one-out encoding when preserving training data matters more. section 8.1.3
- Use ordered target statistics when applying CatBoost: randomly permute training examples and compute each row’s statistics only from preceding rows. section 8.2.1
- Remember that boosting can create prediction shift through reused data even without categorical features; ordered boosting limits gradient information to preceding examples as well. section 8.2.1
