Formulation, Data Contracts & Baselines

A model cannot repair a target defined after the decision, a feature unavailable at prediction time, or an evaluation set that already influenced the work. This section fixes the scientific contract before estimator choice.

Section 1 of 5 · 8 units · about 26 hours

0/8

By the end you can Defend a one-page prediction contract, split and baseline ladder, then show a seeded leakage or availability defect being caught and changing the conclusion after repair.

Units

Build it

Mini project · about 10 to 14 hours

Bike demand contract, split, audits and baseline ladder

Rebuild the hourly UCI Bike Sharing demand problem in your own repository as a contract-first investigation: a one-page prediction contract, an immutable snapshot with a chronological split, an audit suite, a baseline ladder under one harness, and three seeded leakage defects that failing tests must catch. No model tuning happens until the contract and ladder are frozen.

  1. 1Write the contract for next-hour cnt: unit, prediction time, cutoff, horizon, served action, misprediction costs, and an availability table for hour.csv marking same-hour weather as oracle-forecast and casual and registered prohibited for the leak you name, with the feedback loop kept as a monitored exclusion.
  2. 2Store hour.csv with its hash and download date. Build the chronological split, the first year to train and the second to test, asserting no test timestamp precedes train and no prohibited column reaches features.
  3. 3Write the audit suite covering schema and dtypes, missingness, keys and duplicates, time continuity, ranges and normalizations, rare categories and availability. Seed one defect per audit in a copy and show each test fails.
  4. 4Build the baseline ladder in one harness scored by RMSE: train mean, train median, train-last constant, previous row and a label-free linear model, checked against scikit-learn, stating which rung a new model must beat and why.
  5. 5Seed three leakage defects: global scaling before the split, the target-derived casual and registered features, and cross-partition duplicates (copy 500 test rows into train). Catch each with a failing test, report the score before and after repair, and score the contaminated rows separately.
  6. 6Wrap preprocessing in a ColumnTransformer pipeline fitted on train only, write the lineage record (source URL, hash, split rule, seeds, library versions), and run a joblib round trip that asserts identical predictions on five probe rows.
What you hand in
  • contract.md with the availability table, the declared assumptions, the cost statement and the feedback note.
  • The data package: snapshot manifest, split builder and audit suite with its seeded-defect tests.
  • The ladder report: one table of rungs with RMSE and the verdict on whether complexity is justified.
  • The leakage casebook: three defects, each with its failing test, its repair and the conclusion it changed.
How to check it
  • Self-grade with the rubric below
How it's graded

Contract

Pass: Every column is classified with a reason, and prediction time, cutoff and horizon are stated.

Great: The oracle-forecast assumption is priced: the linear rung is rerun without same-hour weather and the change is reported.

Split and audits

Pass: The split is chronological with no prohibited column, and every audit fails on its seeded defect.

Great: One command runs all audits, and a property test shows the split builder never places a test row before a train row.

Baseline ladder

Pass: All five rungs land within a few RMSE points of the reference under one harness.

Great: The report explains why the previous row wins, and why the median loses to the mean on the later test period.

Leakage

Pass: Three defects are each caught by a failing test, with scores before and after repair.

Great: The casebook shows a defect the score cannot reveal (scaler leakage leaves a least-squares RMSE unchanged) and one that only the separately scored rows expose.

Lineage

Pass: The lineage record is complete and the joblib round trip passes.

Great: A fresh clone rebuilds every reported number with one command.

Resources

  • Hands-On Machine Learning with Scikit-Learn and PyTorch - Chapters 1 and 2Aurelien Geron (O'Reilly, 2025)

    Read Chapters 1 and 2 of the book, then run notebooks 01 and 02 and use ml-project-checklist.md for framing, data inspection, test-set creation, preprocessing pipelines, cross-validation, error analysis and persistence. Rebuild the workflow on UCI Bike Sharing with a chronological split and prohibit casual and registered when predicting cnt.

  • scikit-learn - Common pitfalls and pipelinesscikit-learn

    Read Common Pitfalls sections on inconsistent preprocessing and leakage, then Pipeline and ColumnTransformer. Seed global scaling, a target-derived feature and a partition duplicate, and make tests reject each defect.

  • scikit-learn - Cross-validation splittersscikit-learn

    Use the group-aware and time-aware splitter sections plus GroupKFold and TimeSeriesSplit. Choose from the dependence structure and assert that no prohibited group or future timestamp crosses the boundary.

  • Rules of Machine Learning - first controlsGoogle for Developers

    Read Rules 1-5 and 8-9. Turn the existing heuristic into a baseline and test the feature path independently of the learner.

  • UCI Bike Sharing DatasetUCI Machine Learning Repository

    Use hour.csv as the compact integrated dataset. Preserve a raw snapshot and data dictionary, split chronologically, and document why casual and registered are target proxies for cnt.

  • Google ML Problem Framing - framing an ML problemGoogle for Developers

    Read Identify the output you need through Proxy labels and Define the success metrics, including the video-caching threshold analysis, the proxy-issue table, and both Check Your Understanding boxes.