Cleaning, scaling, encoding, and splitting
Before any model can learn, the data needs a thorough clean-up. Here we learn how to wash, organize, and portion our data like a chef prepping ingredients.
Before We Begin
Garbage in, garbage out—you have probably heard that phrase, and it is the single most important rule in machine learning. A model is only as good as the data it trains on. In this lesson we walk through every step of getting raw data ready: handling missing values, scaling numbers so they play nicely together, encoding categories into numbers a model can read, and splitting everything into training, validation, and test sets so we can measure real progress without fooling ourselves.
How this lesson fits
Theory is only half the story. In this module we roll up our sleeves and learn the craft behind every successful ML project: preparing data, engineering features, and strengthening our statistical intuition. These are the skills that separate a notebook experiment from a model you can actually trust.
The big question
What does raw, messy, real-world data need before a model can learn anything useful from it?
Why You Should Care
In the real world, data arrives messy: missing entries, inconsistent formats, wildly different scales. Students who master preprocessing will save hours of debugging and build models that actually generalize. This is the single most time-consuming step in any ML project, and the one professionals say matters most.
Where this is used today
Think of it like this
Think of a restaurant kitchen before dinner service. The chef doesn't start cooking the moment ingredients arrive. First, vegetables are washed, proteins are trimmed, sauces are measured, and stations are organized. Only then does cooking begin. Preprocessing is that mise en place for your model—skip it, and the dish falls apart.
Easy mistake to make
Scaling and encoding are not optional extras—they are critical. A model that receives unscaled features may weight them unfairly, and raw text categories will crash most algorithms entirely.
Think about this first
Imagine you get a spreadsheet where some cells say "N/A," ages range from 0 to 200, and one column mixes "Yes," "yes," and "1." What would you fix first, and why?
Words we will keep using
A model is only as good as its data. Real-world datasets arrive with missing values, impossible outliers, inconsistent formats, and wildly different scales. Preprocessing is the kitchen prep before cooking \u2014 skip it and the recipe falls apart.
This dataset has impossible ages (0, 200), missing incomes (0), null scores, and a text column. Apply preprocessing steps in order and watch the data transform.
| age | income | city | score |
|---|---|---|---|
| 25 | $45,000 | NYC | 72 |
| 0 | $52,000 | LA | 85 |
| 38 | N/A | NYC | 90 |
| 47 | $120,000 | Chicago | null |
| 200 | $38,000 | LA | 65 |
| 31 | $75,000 | Chicago | 78 |
| 29 | N/A | Houston | 82 |
| 55 | $95,000 | NYC | null |
| 42 | $68,000 | Houston | 70 |
| 33 | $58,000 | LA | 88 |
| age | income | city | score |
|---|---|---|---|
| 25 | $45,000 | NYC | 72 |
| 0 | $52,000 | LA | 85 |
| 38 | $0 | NYC | 90 |
| 47 | $120,000 | Chicago | |
| 200 | $38,000 | LA | 65 |
| 31 | $75,000 | Chicago | 78 |
| 29 | $0 | Houston | 82 |
| 55 | $95,000 | NYC | |
| 42 | $68,000 | Houston | 70 |
| 33 | $58,000 | LA | 88 |
Income ranges from $38,000 to $120,000 while age ranges from 25 to 55. Without scaling, a distance-based model would treat income as 1000x more important than age simply because the numbers are bigger.
Min-max scaling squashes every column into so the model treats all features equally.
Never test on what you trained on. The golden rule: split your data into three buckets.