First Simple Pipeline
Unit ID: ML-M03-U07 Estimated active time: 20-30 minutes
Why this matters
As projects grow, modelling code can become messy.
One cell transforms the data. Another cell fits a model. Another cell repeats the transformation on test data. It becomes easy to make mistakes.
A pipeline helps keep steps together.
The idea
A scikit-learn pipeline links steps in order.
For this first module, the pipeline is simple because we use numeric features only:
from sklearn.pipeline import Pipeline
model_pipeline = Pipeline(
steps=[
("model", LogisticRegression(max_iter=1000)),
]
)
This is not impressive yet. It becomes more useful when preprocessing is added later.
Predict
Why introduce a pipeline before we need heavy preprocessing?
Because it builds the habit of keeping the modelling workflow together.
Run or inspect
The pipeline has the same pattern:
model_pipeline.fit(X_train, y_train)
predictions = model_pipeline.predict(X_test)
The learner does not need to master all pipeline details here. The goal is to recognise that a pipeline can behave like a model.
Change one thing
In Module 7, the pipeline will include numeric scaling and categorical encoding. That is when pipelines become essential.
For now, treat this as a preview.
Practice
Answer:
- What does a pipeline keep together?
- Why is that useful for reproducibility?
- Why are we not adding categorical preprocessing yet?
Check and explain
Complete:
A pipeline helps because the same fitted workflow can be used for ______ and ______.
Takeaway
A pipeline keeps the workflow together. Module 3 introduces the habit; Module 7 makes it necessary.
