EasyDeepLearn

Why is target encoding dangerous, and how do you do it safely?

hard

Answer

  • Target encoding replaces a category with the mean target for that category, so the target leaks directly into the feature.
  • Fit it on the whole training set and the model memorizes rare categories, which look perfectly predictive in training and useless later.
  • Do it safely with out-of-fold encoding: for each fold, compute the mapping from the other folds only.
  • Add smoothing toward the global mean so a category with three rows is pulled hard to the prior.
  • Keep the encoder inside the cross-validation pipeline, never as a preprocessing step applied before splitting.
Check yourself — multiple choice
  • It is always safe
  • The target leaks into the feature; use out-of-fold encoding with smoothing, fitted inside the CV pipeline
  • Only use it on numeric features
  • Replace it with one-hot always

Out-of-fold computation plus smoothing, applied inside the pipeline, is what makes it safe.

#encoding#pipelines

Practise Supervised Learning

215 interview questions in this topic.

Related questions