Inventory the damage
Nulls, weird units, duplicated rows, a leakage column. Name them before you impute.
Raw table · houses.csv
Real data is never clean. Toggle a lens to see what is hiding in this table.
| id | area | beds | price | price_next_year |
|---|---|---|---|---|
| 1 | 62 | 2 | 141 | 148 |
| 2 | 74 | 3 | 188 | 197 |
| 3 | - | 2 | 132 | 139 |
| 4 | 91 | - | 224 | 233 |
| 5 | 74 | 3 | 188 | 197 |
| 6 | 58 | 1 | 121 | 126 |
| 7 | 103 | 4 | 256 | - |
| 8 | 67 | 2 | 150 | 158 |
Eight rows. Nothing here is wrong at a glance. That is the trap.
Fit on train only
Fit transforms on train. Apply to test. If you fit on everything, the test already peeked.
Fit order matters
Where you call .fit() on the scaler decides whether test data leaks into training.
Outliers and scaling
Decide what is signal vs sensor glitch. Standardize when distance or gradients care.
Outliers & scale
Two extreme points can drag a whole feature's scale around.
With outliers left in, most points get crushed into a corner. Scale is not a cosmetic step.
Same model, cleaner world
Refit the same regression before and after cleaning. Different world. Same model class.
Same model, same houses
One fit trains on the raw dirty table. The other trains on the cleaned version. Everything else is identical.
Most production ML failures are data failures wearing a model costume.