IntermediateAbout 20 min

    Feature Engineering & Data Leakage

    Read the full article on Substack

    9 min read.

    Amazon had over two million brands in 2019, and three obvious encodings each fail one step later. Watch the hashing trick absorb an unbounded category space, then toggle scale-before-split to see a statistic carry the test set into training.

    Think of it this way: A recipe where the ingredients matter more than the technique. And where one of the ingredients is a taste of the finished dish, which makes every practice run go beautifully and tells you nothing about dinner.

    Three kinds of missingness, and the one that makes deletion safe is very rare.

    Missing not at random

    Missing because of the true value itself. Respondents who did not disclose income tend to have higher income than those who did.

    Removing these rows removes information — the fact that income is missing is itself a signal.

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Leak or safe?

    Sort

    Sort each practice by whether it leaks information from the test set into training.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Leaks

    Drop items here

    Safe

    Drop items here
    6 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    Income missing because high earners decline to disclose it is an example of:

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going