Preparing Data: Scaling, Categories and Pipelines
Models need numbers. Text categories like city must be turned into numbers, and features on very different scales (rupees vs counts) often need scaling.
Models only understand numbers, on sensible scales, with no missing values. Most real ML work is preparing data: encoding categories, scaling numbers and making sure training and real-world data are treated exactly the same way - which pipelines guarantee.
One-hot encoding
Example
Scaling
Example
Pipelines: do every step the same way, every time
A Pipeline joins the preparation steps and the model. It learns the scaling only from training data and applies the same steps to new data - which avoids a common mistake called data leakage.
Example
Most of a data scientist's time goes into getting and cleaning data, not choosing models. Good data beats a clever model.
Key points
- One-hot encode categories.
- Scale numeric features when models need it.
- Pipelines apply the same steps everywhere and prevent leakage.
📝 Test yourself
1. What does one-hot encoding do?
2. Why use a Pipeline?
3. Fill in the scaler that gives mean 0 and spread 1:
from sklearn.preprocessing import
