Target Encoding Leakage Lab 2D: Naive vs K-Fold
Interactive 2D dashboard showing exactly how naive target encoding leaks a row's own label into its feature, inflating training R², and how out-of-fold (K-fold) encoding fixes it — with a draggable/zoomable encoded-vs-target scatter and a live R² gap panel.
Target encoding — replacing a categorical value with the mean target of its category — is one of the most powerful feature-engineering tricks and one of the easiest ways to leak the label into the training set. This lab generates eight synthetic categories, each with its own true mean and a handful of noisy samples, and encodes them two ways: naively (each row's mean includes its own label) and out-of-fold (a K-fold split guarantees no row ever sees itself). Every row is plotted on a draggable, zoomable 2D scatter at (encoded value, true target), with a diagonal marking a perfect encoded = target fit, so you can watch the train cloud collapse onto that diagonal under naive encoding — especially with few samples per category — and spread back out to match the honest held-out cloud the moment K-Fold out-of-fold encoding is switched on. A synchronized bar panel turns the live train/held R² and the leakage gap into a single readable number, and clicking a category swatch isolates its rows across both panels.
Watch naive target encoding bake a row's own label into its own feature — inflating training R² — then switch to out-of-fold K-Fold encoding and watch the leakage vanish, on a draggable, zoomable 2D scatter with a live R² gap panel.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install