Lensa ML
Lensa ML

How Data Preprocessing Works

Cleaning and preparing data before it reaches your model

Step 1 of 6

Raw Data Is Messy

Missing values, different scales, weird formats

NameAgeIncomeCityScoreAlice2550kNYC82Bob?120kLA91Carol350.003NYC?Dave4285kChicago76Eve?1000kLA95Frank3167kChicago?
Missing values (?)
Scale mismatch
Categorical text

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

NameAgeIncomeCityScoreAlice2550kNYC82Bob?120kLA91Carol350.003NYC?Dave4285kChicago76Eve?1000kLA95Frank3167kChicago?
Missing values (?)
Scale mismatch
Categorical text

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

Age Column25R1NULL35R342R4NULL31R6

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

12515007501000IncomeScore

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

Coloris_Redis_Blueis_GreenRed100Blue010Green001Red100Blue010

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

Full Dataset (100%)

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

📋Raw Data🔧HandleMissing📏ScaleFeatures🔢EncodeCategories✂️Train/TestSplit🚀Ready!Pipeline stage: 1 / 6

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.