Skip to content

Target encoding inside folds

Question

You encode industry identifiers using average future returns. Where must that encoding be estimated?

Short answer

Estimate the mapping using training labels only, with out-of-fold or ordered encodings for training rows so their own targets do not trivially enter their features. Apply a smoothed training mapping to validation rows and define a fallback for unseen categories. In time-series settings, ensure every encoded statistic uses labels already available at the decision date. Smoothing helps variance, not leakage.

Original question and answer written by SelfMadeQuant.com.

See the hint and the full worked solution in the question bank (free account).

Open the worked solution

Lessons behind this question

Start with a free lesson: Probability Fundamentals is part of a free topic. Create a free account, no card needed, to read it in full with worked solutions.

Read it free