How Data Preprocessing Works
Cleaning and preparing data before it reaches your model
Raw Data Is Messy
Missing values, different scales, weird formats
Real-world data is never clean. Missing values leave gaps, scale differences make features incomparable, and categorical text can't be fed directly to most algorithms. Data preprocessing fixes these problems before training begins.
Step 1 of 6: Raw Data Is Messy
Missing values, different scales, weird formats
Real-world data is never clean. Missing values leave gaps, scale differences make features incomparable, and categorical text can't be fed directly to most algorithms. Data preprocessing fixes these problems before training begins.
Step 2 of 6: Handling Missing Data
Fill, drop, or impute — strategies for gaps
Dropping rows removes any row with missing values. Simple but wasteful — you lose all other data in that row. Works when few rows are affected.
Step 3 of 6: Feature Scaling
Bringing all features to the same range
Without scaling, Income (0-1000k) dominates Score (0-1). The model treats the bigger numbers as more important — even when they shouldn't be.
Step 4 of 6: Encoding Categories
Turning words into numbers machines understand
One-hot encoding creates a binary column for each category. No fake ordering is imposed — Red is not "greater than" Blue. Use this for nominal (unordered) categories.
Step 5 of 6: Train-Test Split
Never test on training data
Training data teaches the model. Validation data tunes hyperparameters. Test data gives the final, unbiased score. If the model ever sees test data during training, your evaluation is meaningless — the model simply memorizes answers.
Step 6 of 6: The Preprocessing Pipeline
Putting it all together in order
A preprocessing pipeline chains these steps in order: handle missing values first (so scaling doesn't break), then scale, then encode, and split last so test data stays untouched. In practice, use tools like scikit-learn's Pipeline to keep this reproducible.