The Raw Material: Data Engineering for Machine Learning
Before AI can become smart, the data needs to behave. How that's done.
You've learned how models optimize their parameters via gradient descent and regression. But what goes INTO the model? Raw data from the real world is messy, incomplete, and measured on wildly different scales.
This article covers the three pillars of data preparation — the work that happens before a single training step. Because the most expensive GPU cluster in the world can't save a model trained on garbage data.
Feature Engineering: Choosing the Right Inputs
Feature Engineering
Consider a concrete example: real estate price prediction. The raw data contains an address as text — practically useless to a model. Feature Engineering transforms it into meaningful numbers:
Categorical data like colors (red, blue, green) requires special treatment: One-Hot Encoding creates a separate binary column for each value (is_red, is_blue, is_green). This lets the algorithm work with categorical data without imposing an artificial ordering.
Misconception: More Features = Better Model
Feature quality outweighs model complexity. A simple linear model with excellent features regularly beats a complex neural network with bad features.
Interactive: The Data Engineering Pipeline
Press Play and watch how raw data gets prepared step by step.
The typical data preparation process in five steps: From messy raw data through cleaning, feature engineering, and scaling to a model-ready dataset.
Click "Play" to see the RAG pipeline step by step.
The pipeline is strictly sequential: each step builds on the previous one. The order is critical — scaling before the split causes data leakage.
Missing Values: Holes in the Data
Missing Values
There are three established strategies, each with clear pros and cons:
Simple but wasteful: Remove all rows with missing values. With 20% missing values, the dataset shrinks from 1,000 to 800 entries.
Preserves data but introduces assumptions: Fill empty fields with median or mean. Keeps all 1,000 entries, but assumes "average health."
Third Strategy: Indicator Variable
Concrete example: A medical dataset has 20% missing blood pressure values. You suspect the data is missing because obese patients refused to be measured. Deletion loses 200 records. Median imputation with 120 mmHg assumes "normal value." An indicator variable reveals the actual reason.
Normalization & Standardization: Getting Everything on the Same Scale
Feature Scaling
Worked Example: Scaling Three Features
Deep Dive: Why Scaling Speeds Up Gradient Descent
Misconception: Normalization Changes the Data
Deep Dive: Data Leakage — The Hidden Trap
Interactive: Sort Pipeline Steps
In what order must data preparation steps be executed? Sort the pipeline — but beware: the wrong order causes data leakage!
Sort the pipeline steps into the correct order. Hint: Think about data leakage — which step absolutely must come early?
Key Takeaways
Learning Goals
- Explain with your own example why raw text data (e.g., an address) is not a good feature for an ML model.
- You have a dataset with 30% missing temperature values from a sensor. Which of the three strategies would you choose and why?
- Calculate the Min-Max normalization for x=75 with a range of 0 to 200.