Section 2 of 7 · Programming & Data Foundations
Build Your First Machine Learning Model
Move from reading data to building a measurable prediction system. This project-first section introduces problem framing, the exact moment a prediction is made, chronological validation, leakage-safe preprocessing, a simple estimator, error analysis and reproducible project artifacts before the deeper mathematical treatment in later stages.
5 units 6 topics 0/5
Units
5 in this section
- 2.1 Frame a prediction task and choose a baseline explain · derive2 h
- 2.2 Split data by time and prevent leakage implement · explain · measure3 h
- 2.3 Build a preprocessing pipeline and first model implement · measure3 h
- 2.4 Evaluate the model and inspect its errors measure · explain3 h
- 2.5 Make the experiment reproducible and explain its limits implement · explain2 h
Before moving on
Checkpoint
Build a bike-demand regression baseline for the start of each hour using only calendar information available at that moment. Train on 2011 and keep 2012 as a final chronological test. Exclude target-derived fields and observed weather measurements from model inputs, compare against a naive baseline, inspect errors and reproduce the documented result from a clean checkout.
Deliberately out of scope
Leave for later
- Hyperparameter search and model ensembles
- Causal interpretation of observational feature importance
- Production deployment, model monitoring and automated retraining
Resources for this section
Shared by every unit above
- 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.
- 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. - 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.
Apply the section
Mini-project · Predict hourly bike-sharing demand with a leakage-safe baseline (6 to 8 h)
Train a first regression model on the UCI Bike Sharing hourly dataset. Define the prediction moment as the start of each hour, before that hour’s rentals and observed weather are known. Use
cnt as the target, keep the split chronological (2011 train, 2012 final test), and use only known calendar inputs such as season, mnth, hr, holiday, weekday and workingday. Exclude casual, registered, cnt, instant, dteday, yr, weathersit, temp, atemp, hum and windspeed from model features. The observed weather fields may be used for exploratory plots and post-hoc error slices, but not as predictors under this prediction contract. Compare a DummyRegressor baseline with a preprocessing-and-estimator Pipeline, evaluate MAE and RMSE, inspect error slices, and document the limits of the experiment. This is a learning project, not a production forecasting system.Steps
- Write the problem contract: one hourly observation,
cnttarget, prediction at the start of the hour, calendar inputs known at that moment, MAE as an interpretable error measure and a simple baseline. - Sort by
dteday; train on 2011 and reserve 2012 for final evaluation. Exclude target-derived fields, IDs, split-only fields and observed weather measurements from X. - Fit a training-set mean DummyRegressor and a RandomForestRegressor pipeline with a ColumnTransformer for the calendar categorical and numeric columns.
- Evaluate both predictors on the same 2012 test rows with MAE and RMSE; inspect residual plots and errors by hour, weekday and observed weather category. Weather is used only to analyse errors after prediction, not as a model input.
- Save the training code, feature list, dependency versions and metrics. Re-run from a clean environment and write limitations in the README.
Deliverables
- A reproducible notebook or small Python project with explicit data and model contracts.
- Chronological split evidence and a feature-leakage audit.
- Baseline and model predictions with MAE and RMSE.
- Error plots and at least two clearly defined error slices.
- A README containing the dataset citation, license, run instructions, environment and limitations.
Checks
- target · `cnt` is the target and is never included in the feature matrix.
- leakage · `casual` and `registered` are excluded because they compose `cnt`; `instant`, `dteday` and `yr` are not predictors.
- availability · The prediction is made at the start of the hour. Only calendar features known then are model inputs; observed weather fields are excluded and reserved for exploration/error slices.
- split · 2011 is used for training and the untouched 2012 period for final testing.
- baseline · DummyRegressor and the trained model are evaluated on the same held-out rows.
- reproducibility · A clean run reproduces the split and evaluation record.
Rubric
| Criterion | Pass | Strong |
|---|---|---|
| Problem and data contract | Defines the target, features, prediction moment and metric. | Also justifies why these inputs are available at prediction time. |
| Evaluation validity | Uses chronological split, excludes leakage fields and reports a baseline. | Adds explicit assertions and audits preprocessing boundaries. |
| Model evaluation | Reports MAE/RMSE and compares the estimator with the baseline. | Adds readable error slices and explains limitations of the test period. |
| Reproducibility | Project can be run from documented steps. | Records data provenance, versions, split rules and artifacts with clear limitations. |
Feeds into: Classical Machine Learning: Formulation, Data Contracts & Baselines, where the same workflow is formalized and extended to cross-validation, model choice and statistical evaluation.