Unit 1.5 · about 3 h
132 / 324Schema, 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
- Data inspection and correlation audit patternHands-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_proximityvalue_counts,describe,hist) and Looking for Correlations (corrmatrix sorted onmedian_house_value,scatter_matrix,median_incomescatter) with Experimenting with Attribute Combinations (rooms_per_house,bedrooms_ratio,people_per_house) - Missing-value audit and the Explore checklistHands-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 (dropnasubset, drop column, medianfillna),SimpleImputeron the numeric subset withstatistics_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.
- Bike dictionary and normalization provenanceUCI Bike Sharing Dataset
Variables Table roles, types, and descriptions; Additional Variable Information normalizations (
tempandatempmin/max formulas on the hourly scale,humdivided by 100,windspeeddivided by 67); Dataset Information no-missing-values statement; Dataset Files sizes (hour.csv1.1MB,day.csv56.2KB,Readme.txt) - Freshness and export checks as availability auditsRules 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
dtypesfirst (dtedayloads as astring, not adatetime), then missingness (the page reports none and a direct count finds 0 nulls in 17379 hour rows), then keys and duplicates (instantunique, 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_dummiesbuilds 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. Bikeweathersittakes 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.
casualandregisteredare label parts,instantis a row id, anddtedaymust be parsed into cutoff-respecting parts. Record per-feature availability beside the audit.
Reproduce closed-book
(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
infoanddescribealone.describeskips strings (ocean_proximityneedsvalue_counts) and hides thedteday-as-string problem; checkdtypesexplicitly. - Reading normalized columns as raw units.
temp0.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
-
The imputed housing frame shows no nulls. How do you verify the imputer learned the right values?
Compareimputer.statistics_against the train numeric medians; they must match for the median strategy, and the imputer must befiton train numerics only. -
tempreads 0.24 inhour.csv. What is it in Celsius?About 3.3 C: 0.24 times (39 minus -8) plus -8 equals 3.28. Quote the hourly-scale bounds (-8/+39) with the number. -
get_dummiesgivesINLANDandNEAR BAYcolumns on one frame and<2H OCEANandISLANDcolumns on another. What breaks, and what does the notebook's fitted encoder do instead?get_dummiesbuilds columns from whatever values each frame holds, so two(2, 2)frames have disjoint names and misalign. The encoder fitted on the training set keeps its five learned columns; withhandle_unknown=ignorethe unseen<2H OCEANbecomes an all-zero row, whileISLAND, a known category, gets its own column. -
Which bike columns are unavailable as hourly-
cntfeatures, and why?casualandregistered(label parts: their sum equalscnton every row),instant(row id), and rawdteday(needs parsing into cutoff-respecting parts); any same-hour aggregate realized after prediction time is out too.
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
- 1.6 Training-only imputation, scaling, encoding and learned state Feed audited columns into train-only transformers with an unknown-category policy.
- 1.8 Snapshots, lineage, pipeline serialization and serving parity Snapshot the audited raw data and dictionary under versioned lineage.
Comes after
- 1.4 Leakage: target, future, entity, duplicate, preprocessing and feedbackBuild the audit suite that catches these defects routinely.
- 5.9 Covariate, label and concept shift, drift and label delayFeed drift monitors with audited schema and provenance.
Resources for this unit
- Hands-On Machine Learning with Scikit-Learn and PyTorch - Chapters 1 and 2 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 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 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 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 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 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.