Based on book of Geron
Here is some example of preparation when we want to run some process on machine learning before we choose the model.
#lets create the data pipeline
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
num_pipeline = Pipeline([
('imputer', SimpleImputer(strategy="median")),
('attribs_adder', CombinedAttributesAdder()),
('std_scaler', StandardScaler()),
]
)
housing_num_tr = num_pipeline.fit_transform(housing_num)
and the idea why this process exist is
This code builds a data-cleaning machine (a pipeline) that automatically prepares your data before training a machine-learning model.
Instead of cleaning data step by step manually,
➡️ The pipeline does all steps in the correct order, every time.
🧱 What the pipeline contains (in plain English)
1. Imputer
('imputer', SimpleImputer(strategy="median"))-
Fills empty or missing values in your dataset
-
Uses the median of the column
-
Make sure the model won’t crash because of missing data
👉 Like filling empty boxes so everything is complete.
2. Attribute Adder
('attribs_adder', CombinedAttributesAdder())-
Adds new useful features (like rooms per household, etc.)
-
Helps the model learn better patterns
-
You wrote this transformer earlier
👉 Like adding extra helpful information the model didn’t have before.
3. Standard Scaler
('std_scaler', StandardScaler())-
Makes all numbers on a similar scale (mean 0, std 1)
-
Prevents big numbers from dominating small numbers
-
Important for many ML algorithms
👉 Like making all features “fair” before the model uses them.
📦
Putting it all together: Pipeline
num_pipeline = Pipeline([ ... ])The pipeline arranges all steps in the correct order:
-
Fix missing values
-
Add new attributes
-
Scale the features
👉 Think of it like a factory assembly line for data.
🚀
Finally, run the pipeline on the data
housing_num_tr = num_pipeline.fit_transform(housing_num)This:
-
Fits the pipeline
-
Transforms the data
-
Returns the cleaned, improved numeric dataset
👉 Now your data is ready for the model.
ðŸ§
In one simple sentence:
And how it runs in model

0 Comments