DATA PREPARATION · 8 MIN
Cleaning & Scaling Data
Models learn from data, so messy data means a messy model.
PIXEL explains
- Handle missing values: drop the row or fill it (mean, median, most common).
- Turn categories into numbers with one-hot encoding.
- Scale features so big numbers don't dominate: min-max to 0–1, or standardise to mean 0.
Real world: Before cooking, you wash, peel and chop — data prep is the same step for ML.
Code
ages = [20, None, 40, 30]
known = [a for a in ages if a is not None]
mean = sum(known) / len(known)
filled = [a if a is not None else mean for a in ages]
lo, hi = min(filled), max(filled)
print([round((a - lo) / (hi - lo), 2) for a in filled])Output ›
[0.0, 0.5, 1.0, 0.5]Try it in the online compiler →Checkpoint quiz
Min-max scaling maps values into…