Unit 2.3 · about 3 h
7 / 324Build a preprocessing pipeline and first model
A model is more than an estimator call. Real datasets require consistent transformations, and a pipeline makes the preprocessing/model contract explicit while reducing a major source of leakage.
- implement
- measure
You can now
- Fit a DummyRegressor baseline on the training partition.
- Build a ColumnTransformer for categorical and numeric features.
- Chain preprocessing and an estimator in a scikit-learn Pipeline.
- Fit the pipeline only on training data and generate test predictions.
- Use only the calendar feature contract:
season,mnth,hr,holiday,weekdayandworkingday; keep observed weather measurements outside the model pipeline.
Covers
- Preprocessing pipelines and baseline estimators
Study, in this order
3 steps
- Intro to Machine LearningKaggle Learn — Intro to Machine Learning
Complete How Models Work, Your First Machine Learning Model and Model Validation; then inspect the random-forest lesson.
- Pipelines and composite estimatorsPipelines and composite estimators
Study Pipeline and ColumnTransformer and build one preprocessing-and-regression pipeline.
- Machine Learning Crash CourseGoogle Machine Learning Crash Course
Use the regression and numerical/categorical data modules as conceptual support for the feature transformations.
Focus on
- DummyRegressor as a transparent baseline
- ColumnTransformer for separate numeric and categorical columns
- OneHotEncoder for categorical features
- Pipeline fit/predict boundaries
- Calendar-only feature contract based on information available at the start of the hour
Reproduce closed-book
season, mnth, hr, holiday, weekday and workingday. Keep transformations inside the pipeline and generate one prediction vector for the untouched test partition.Traps
- Do not fit preprocessing outside the pipeline on all rows.
- Do not compare models evaluated on different splits.
- Do not assume a more complex model is better without a held-out improvement.
Practice
Kaggle Intro to Machine Learning exercises
Build the first estimator in a fresh notebook, then adapt the pattern to the UCI bike-sharing feature contract.
Start with a simple estimator; don't tune hyperparameters yet.
Self-test
-
What does ColumnTransformer provide in this project?
It applies different transformations to different column groups, such as one-hot encoding categorical columns while passing numeric columns through. -
Why is the baseline fitted on the same training partition as the model?
Both predictors must face the same information boundary and test observations for the comparison to be fair.
Completion criterion
Stop when
The baseline and calendar-only model pipeline fit without reading the test target, and the model produces one prediction per test observation.
Mark passed, then open 2.4 Only mark this when you can do it without notes.Leads to
- 2.4 Evaluate the model and inspect its errors Follow the practical starter sequence; each unit uses the artifact from the previous step.
Comes after
- 2.2 Split data by time and prevent leakageFollow the practical starter sequence; each unit uses the artifact from the previous step.
Resources for this unit
- Kaggle Learn — Intro to Machine Learning Complete the lessons on how models work, data exploration, the first model, model validation, underfitting/overfitting and random forests. Reproduce the exercises in a fresh notebook.
- Google Machine Learning Crash Course Use the modules on regression, numerical and categorical data, datasets/generalization/overfitting, and classification metrics as a structured conceptual companion. The course is free and includes interactive exercises.
- Pipelines and composite estimators Study
PipelineandColumnTransformer. Keep preprocessing inside the pipeline so transformations are fitted only on the training partition and applied consistently at evaluation time.
Also in this section
- Bike Sharing Dataset Use the hourly dataset (17,389 records) for a first regression project. Sort chronologically; use 2011 for training and 2012 as the untouched final test period.
cntis the target. Excludecasual,registered,cnt,instant,dtedayandyrfrom the model feature matrix; usedtedayonly to sort/split. - Introduction to Machine Learning Problem Framing Complete the short course on deciding whether ML fits the problem, framing the model output and choosing success metrics before touching the estimator.
- Common pitfalls and recommended practices Read the sections on inconsistent preprocessing and data leakage. Use the wrong/right examples to audit the project before trusting the reported test score.
- TimeSeriesSplit Read why ordinary cross-validation can train on future observations and evaluate on the past. The starter project uses one chronological year holdout; use TimeSeriesSplit when extending it to repeated time-aware validation.
- Model evaluation: regression metrics Use the regression metric definitions for MAE, MSE/RMSE and R-squared. Explain the units and limitations of each metric instead of reporting a score without context.
- Machine Learning in Python with scikit-learn (MOOC) Use as the free, more thorough follow-on after this guided first model. Its static course and notebooks are openly available; the materials are published under CC BY.
- Model persistence Read the security and version-compatibility warnings before saving an estimator. Treat the training code, package versions, data split and metrics as the reproducible artifact, not just a serialized model file.