7 routes42 sections324 units

Unit 1.5 · about 3 h

132 / 324

Schema, provenance, missingness, duplicate and availability audits

Audits turn data hunches into checked facts. Every leakage repair in this section starts as one failing audit.

  • implement
  • measure

You can now

  • Write tests for schema, duplicates, target-derived features, future timestamps, preprocessing scope, and train/evaluation contamination.
  • Measure missingness, duplicate rates, unknown-category rates, and class prevalence per slice, and record per-feature availability at prediction time.
  • Preserve a raw snapshot with its data dictionary and provenance before any cleaning.

Covers

  • Schema, types, provenance, missingness and duplicate audits
  • Categorical unknowns, class prevalence and feature availability

Study, in this order

4 steps

  1. Data inspection and correlation audit pattern
    Hands-On Machine Learning with Scikit-Learn and PyTorch - Chapters 1 and 2

    Book Chapter 2: Take a Quick Look at the Data Structure (printed pp. 54-57), Look for Correlations and Experiment with Attribute Combinations (pp. 65-69). Notebook 02: Take a Quick Look at the Data Structure (head, info, ocean_proximity value_counts, describe, hist) and Looking for Correlations (corr matrix sorted on median_house_value, scatter_matrix, median_income scatter) with Experimenting with Attribute Combinations (rooms_per_house, bedrooms_ratio, people_per_house)

  2. Missing-value audit and the Explore checklist
    Hands-On Machine Learning with Scikit-Learn and PyTorch - Chapters 1 and 2

    Book Chapter 2: Clean the Data (printed pp. 70-73). Notebook 02: Data Cleaning: null-row audit with isnull().any(axis=1), the three options (dropna subset, drop column, median fillna), SimpleImputer on the numeric subset with statistics_ checked against manual medians; plus the checklist Explore the data steps (name, type, percent missing, noise, usefulness, distribution per attribute, target identification, documentation)

    Depth · Read the audit pattern here. The graded audit runs on Bike, not housing.

  3. Bike dictionary and normalization provenance
    UCI Bike Sharing Dataset

    Variables Table roles, types, and descriptions; Additional Variable Information normalizations (temp and atemp min/max formulas on the hourly scale, hum divided by 100, windspeed divided by 67); Dataset Information no-missing-values statement; Dataset Files sizes (hour.csv 1.1MB, day.csv 56.2KB, Readme.txt)

  4. Freshness and export checks as availability audits
    Rules of Machine Learning - first controls

    Rule 8: Know the freshness requirements of your system; Rule 9: Detect problems before exporting models

Focus on

  • Audit in fixed order: shape and dtypes first (dteday loads as a string, not a datetime), then missingness (the page reports none and a direct count finds 0 nulls in 17379 hour rows), then keys and duplicates (instant unique, zero duplicated full rows), then time continuity (75 rows do not follow the previous clock hour, so the previous row and the previous hour differ), then ranges, normalizations, prevalence and availability.
  • The checklist Explore list is the procedure: name, type, percent missing, noise, usefulness, and distribution per attribute, plus target identification and a sorted correlation pass. Document everything in the notebook.
  • Unknowns and prevalence are decided before fitting. In the housing notebook, get_dummies builds whatever columns each frame holds, while the encoder fitted on the training set keeps its five categories; the test value <2H OCEAN, a misspelling of <1H OCEAN, is the unseen one. Bike weathersit takes all four values 1 to 4, but category 4 appears on only 3 of 17379 rows, so a split can easily miss it.
  • A column present in the CSV may still be unavailable live. casual and registered are label parts, instant is a row id, and dteday must be parsed into cutoff-respecting parts. Record per-feature availability beside the audit.

Reproduce closed-book

Closed-book, run the Bike audit from memory: shape (17379, 17), zero nulls, instant unique, zero duplicated rows, dteday string-to-datetime parse, weathersit/holiday/season value sets, the cnt identity check, and the file-versus-page count note (17379 rows against 17389 stated). Emit a one-table dictionary with role, type, and availability per column.

Traps

  • Trusting info and describe alone. describe skips strings (ocean_proximity needs value_counts) and hides the dteday-as-string problem; check dtypes explicitly.
  • Reading normalized columns as raw units. temp 0.24 is not 0.24 C; invert \((t-t_{\min})/(t_{\max}-t_{\min})\) with the stated hourly minima and maxima (about 3.3 C for 0.24) before any physical claim.
  • Counting the landing page as the audit. The page states 17389 instances with no missing values; verify both against the download (17379 rows, 0 nulls) and record version and date.

Practice

The section mini-project covers this: the full Bike audit suite (schema, types, provenance, missingness, duplicates, unknowns, prevalence, availability) with seeded defects that failing tests must catch.

Self-test

  1. The imputed housing frame shows no nulls. How do you verify the imputer learned the right values?

  2. temp reads 0.24 in hour.csv. What is it in Celsius?

  3. get_dummies gives INLAND and NEAR BAY columns on one frame and <2H OCEAN and ISLAND columns on another. What breaks, and what does the notebook's fitted encoder do instead?

  4. Which bike columns are unavailable as hourly-cnt features, and why?

Completion criterion

Stop when

Your audit script runs on a fresh download and reproduces the shape, null, duplicate, and identity numbers plus a per-column availability column without edits.

Mark passed, then open 1.6 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • Hands-On Machine Learning with Scikit-Learn and PyTorch - Chapters 1 and 2
    Aurelien Geron (O'Reilly, 2025)primarycourse
    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.
  • Rules of Machine Learning - first controls
    Google for Developerssupportapplication
    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 Dataset
    UCI Machine Learning Repositorysupportpractice
    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.

Also in this section

  • scikit-learn - Common pitfalls and pipelines
    scikit-learnrequiredreference
    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 splitters
    scikit-learnsupportreference
    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.
  • Google ML Problem Framing - framing an ML problem
    Google for Developerssupportapplication
    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.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels