ML data engineering
Data Profiling and Statistical Baselines
Profile distributions, missingness, relationships, slices, and reference editions for investigation and review.
By the end you can
- Build profiles for distributions, missingness, cardinality, relationships, and slices
- Distinguish description, validation, anomaly detection, and monitoring
- Choose references that reflect seasonality, source versions, and intended comparisons
- Use profiles to guide investigation without turning every historical range into a rule
Example
Global stability, local collapse: a factor of 10 to beyond 100 between slices
Always profile important slices and intersections, not only the full table. An aggregate can hold perfectly still while a subpopulation inside it collapses.
The largest published demonstration of this is a government test rather than an argument. In December 2019 the National Institute of Standards and Technology published NISTIR 8280: 18.27 million images of 8.49 million people, run through 189 algorithms from 99 developers. The executive summary section headed “WHAT WE FOUND” states the result without hedging. “Across demographics, false positives rates often vary by factors of 10 to beyond 100 times.” False positive rates were highest for West and East African and East Asian people, and lowest for Eastern Europeans, on the same high-quality application photos. One reported error rate, two orders of magnitude between the slices inside it.
The U.S. Government Accountability Office restated the same measurement in its own words: “In verification algorithms, false positive rates for white males and black females varied by factors of 10 to more than 100, meaning the lowest-performing algorithm could be over 100 times more accurate on white male faces than on black female faces”. It confirmed the scale of the test too: “NIST tested 189 mostly commercial algorithms from 99 developers”. Nothing in a single global accuracy figure carries that information. Neither does a one-axis breakdown. The intersectional profile is what exposed it.
The same shape recurs in ordinary pipelines. Profile each of these axes on its own, and then their intersections:
- Application version: total event volume stays flat while one release stops emitting purchase confirmations.
- Geography: median delivery time is stable while a newly opened region arrives with ninety percent of postal codes missing.
- Class balance: aggregate fraud prevalence is unchanged because one merchant segment rises exactly as another disappears.
- Device model: fleet average temperature stays in range after half of one sensor model freezes at a constant value.
- Language and script: the global text length distribution is stable while a tokenizer update truncates one script disproportionately.
Case
Gender Shades: 34.7% for darker-skinned women, 0.8% for lighter-skinned men
An overall accuracy number can hide a subgroup failure completely, and Gender Shades is the standard demonstration of it.
Buolamwini and Gebru tested three commercial gender classifiers against a benchmark balanced for gender and skin type. They had to build that benchmark, because the sets in common use, IJB-A and Adience, were overwhelmingly lighter-skinned — 79.6% and 86.2%. They found that “darker-skinned females are the most misclassified group (with error rates of up to 34.7%)”. At the other end of the same table, “the maximum error rate for lighter-skinned males is 0.8%”.
A second record of the work states the ordering with a different set of statistics. The MIT Media Lab publication page reports that “Darker females were 32 times more likely to be misclassified than lighter males”, and that “37% - 83% of classification errors resulted from the misclassification of darker females”, with lighter males contributing least to overall error, at “.4% - 3%”. The project site reports the same ordering, with IBM’s gap between lighter males and darker females at 34.4 points.
No single-axis report on gender would have shown any of that. Neither would a single-axis report on skin type. The failure lived in the intersection, which is precisely the cell that a global metric averages away.
“Data quality” is too broad to debug
A dataset can be complete but stale, valid but unrepresentative, unique but temporally leaked. It can be statistically stable while one critical region disappears. Calling all of these “quality” hides the mechanism.
Profiling summarizes what is present before the team decides what should be present. It measures types, ranges, categories, quantiles, missingness, cardinality, duplicates, time coverage, and relationships.
Validation compares data against declared expectations. Anomaly detection looks for unusual departures. Observability connects those signals to lineage, incidents, ownership, and response.
The purpose of profiling is not a decorative dashboard. It is to discover assumptions, expose population structure, and decide which failures deserve enforceable controls.
The cost of skipping this work has been measured. Sambasivan and colleagues reported in 2021 on evidence drawn “from interviews with 53 AI practitioners in India, East and West African countries, and USA”. They found data cascades “pervasive (92% prevalence), invisible, delayed, but often avoidable”. Ninety-two percent is the prevalence. The word to notice is delayed. The damage surfaced far downstream from the data step that caused it, which is why the profile is the cheapest place to stop a cascade and the model evaluation is the most expensive.
Profile first to learn the data; validate later against reviewed expectations.
Visual
Six dimensions that fail independently: 15,841 valid cases that were never counted
Validity, completeness, consistency, timeliness, representativeness and historical correctness are separate properties. One can pass while another fails.
Between 25 September and 2 October 2020, Public Health England lost 15,841 positive COVID-19 cases from its reported figures. Every row that survived was valid, internally consistent and delivered on time. The population was simply incomplete. Michael Brodie, the Interim Chief Executive of Public Health England, set out the mechanism on GOV.UK on 4 October 2020: “A technical issue was identified overnight on Friday 2 October in the data load process that transfers COVID-19 positive lab results into reporting dashboards. After rapid investigation, we have identified that 15,841 cases between 25 September and 2 October were not included in the reported daily COVID-19 cases.” The stated cause was a file boundary — “some files containing positive test results exceeded the maximum file size”. Over 75% of the loss, 11,968 cases, was concentrated in the last three days, 30 September to 2 October.
Completeness failed alone, and the consequence was quantified afterwards. Fetzer and Graeber treated the incident as a natural experiment in PNAS: “Because of a coding error involving spreadsheet data used by the health authorities, a total of 15,841 COVID-19 cases (around 20% of all cases) failed to have timely contact tracing”. Cases that were properly traced were associated with 63% fewer subsequent infections and 66% fewer subsequent COVID-19-related deaths over six weeks.
A composite quality score would have rated this dataset healthy. Five dimensions passing, one silently failing at a file-size limit, and roughly a fifth of the population gone.
Validity
Values conform to types, domains, formats, ranges, and cross-field rules.
Completeness
Expected records and fields are present for the intended population.
Consistency
Definitions, units, identities, and transformations agree across sources and stages.
Timeliness
Data arrives and becomes available within the consumer’s freshness objective.
Representativeness
Coverage reflects the deployment population and important slices adequately.
Historical correctness
Rows respect time boundaries, versions, and the information available at decision time.
No single quality score can preserve the meaning of all six dimensions.
Analogy
An examination, not a diagnosis
Temperature, blood pressure, symptoms, history, and laboratory values are what a doctor records when examining a patient. The measurements describe the patient before the clinician decides what they mean. Validation resembles checking known safe ranges or contraindications. Anomaly detection notices unusual combinations. Observability connects the result to prior visits, medication changes, and responsible care teams. Datasets contain populations rather than one patient, and a healthy global average can coexist with severe harm to a small but important slice.
Profiling creates evidence; domain and consumer context determine which evidence becomes a quality requirement.
Steps
Build a profile that supports decisions
Organize the report around likely failure modes and consumers, not around every statistic a tool can compute: confirm grain and keys, profile fields and time, compare slices, examine relationships, and convert findings into controls.
Step four — examine relationships, cross-field invariants, target associations and suspicious shortcuts — is the step teams treat as optional. It is where a defect can sit that no distribution check will ever raise.
One commercial risk-prediction algorithm, from a class of tools applied to roughly 200 million people in the United States each year, shows what that looks like. Obermeyer and colleagues dissected it in Science in 2019. The feature distributions were unremarkable. The target was the defect. The algorithm predicted health-care cost rather than illness, so Black patients at the same risk score were considerably sicker than white patients at that score. The abstract states the size of it in one sentence: “Remedying this disparity would increase the percentage of Black patients receiving additional help from 17.7 to 46.5%.”
Regulators named the same mechanism on the same date. The New York State Department of Financial Services and Department of Health wrote jointly to UnitedHealth Group Incorporated about that algorithm, Optum’s Impact Pro: “By relying on historic spending to triage and diagnose current patients, your algorithm appears to inherently prioritize white patients who have had greater access to healthcare than black patients.”
A profile that stopped at types, ranges and missingness would have passed this dataset without comment. Step four is for profiling how the target itself associates with slices — the label, not only the features. It belongs in the profile, not in a fairness review held after the model ships.
1. Confirm grain and keys
Measure row uniqueness, examples per entity, duplicates, and join multiplicity.
2. Profile fields and time
Summarize types, ranges, categories, missingness, timestamps, freshness, and revisions.
3. Compare slices
Inspect important populations, source systems, versions, labels, and temporal cohorts.
4. Examine relationships
Test cross-field invariants, correlations, target associations, and suspicious shortcuts.
5. Convert findings into controls
Assign owner, severity, threshold, response, and exception policy to selected checks.
A useful profile ends with decisions about controls, data gaps, and further investigation.
Key idea
In range, type-valid, and 170 kilometres low
A current maximum may reflect limited history rather than a true domain limit. New categories, seasonal peaks and legitimate expansion can all violate a constraint inferred from one sample. The opposite error is quieter. A domain-valid range can be too weak to catch anything, because the values are each individually plausible and wrong together.
The Mars Climate Orbiter was lost on 23 September 1999 in exactly that way. The Mishap Investigation Board’s Phase I Report of 10 November 1999 states the cause in its executive summary: “The MCO MIB has determined that the root cause for the loss of the MCO spacecraft was the failure to use metric units in the coding of a ground software file, “Small Forces,” used in trajectory models.” The SM_FORCES file supplied thruster data in English units where the interface specification required metric. No value was out of range. No type was violated. Nothing in the file looked anomalous. The error accumulated undetected across a nine-month cruise, and “At the time of Mars insertion, the spacecraft trajectory was approximately 170 kilometers lower than planned”. The U.S. Government Accountability Office recorded the same finding — “A NASA mishap investigation team determined that the loss was due to the mistaken use of English rather than metric units in the navigation software. As a result, an incorrect trajectory was computed and the spacecraft was lost.” — against a $75 million development cost.
A statistical band learned from observed values cannot catch a defect of that shape. The defect is in the meaning of the numbers, not in their spread. Only a declared unit, checked as a contract at the interface, would have fired. Use three layers — impossible values, contract expectations, and statistical warning bands — and keep hard failures rare, interpretable, and tied to a clear consumer risk.
Thresholds should encode reviewed expectations and response costs, not frozen observations from one sample.
Choose references that match the question: 100 misses in 108 weeks
Compare current data with several references: the previous period, the same seasonal period, the training snapshot, serving traffic, and a known-good release. Each comparison answers a different question. A day-over-day reference catches sudden pipeline breaks but may alert on weekends. A year-over-year reference captures seasonality but can miss recent product changes.
Google Flu Trends is what a baseline looks like when it is fitted once and never re-compared. The model was built against CDC influenza-like-illness reports, then drifted away from them in one direction for years. Lazer and colleagues counted the drift in Science in 2014: “GFT also missed by a very large margin in the 2011–2012 flu season and has missed high for 100 out of 108 weeks starting with August 2011”. A hundred misses out of a hundred and eight is not noise. The errors were autocorrelated and seasonal, the signature of a stale reference rather than of a surprising world. Three-week-old CDC data projected current prevalence better than the model did.
An independent reassessment in PLOS Computational Biology found the same failure at national, regional and New York City scales: “We identified substantial flaws in the original and updated GFT models at all three geographic scales, including completely missing the first wave of the 2009 influenza A/H1N1 pandemic, and greatly overestimating the intensity of the A/H3N2 epidemic during the 2012/2013 season.”
Slice references need adequate sample size and stable definitions. It is possible to state the size at which a slice stops being trustworthy, instead of leaving it to judgement. Ofqual did so for its 2020 grade standardisation model in England: “Where schools and colleges had a relatively small cohort for a subject – fewer than 15 students when looking across the current entry and the historical data – the standardisation model put more weight on the CAGs”, the centre assessment grades supplied by teachers. Its interim report of 13 August 2020 gives the reason in its executive summary: “However, there is no statistical model that can reliably predict grades for particularly small groups of students. We have therefore used the most reliable evidence available, which is the CAGs.” The regulator set its statistical threshold at 5, below which no significance test could establish a real difference. It also reported that 96.4% of final calculated grades were within one grade of the submitted centre assessment grade, an aggregate that looked reassuring.
The Office for Statistics Regulation later identified where the checking had stopped: “For output data, the regulators undertook a wide range of analysis, largely at an aggregate level. There was limited human review of outputs of the models at an individual level prior to results day.”
Store the reference version and comparison method with every alert. An anomaly without a named baseline cannot be reproduced or interpreted. A baseline that is never re-compared can be wrong in the same direction for a hundred weeks running.
Reference selection is part of the quality rule because it defines what “changed” means.
Key takeaways
- Data quality decomposes into validity, completeness, consistency, timeliness, representativeness and historical correctness, and they fail independently: Public Health England's 15,841 lost cases were valid, consistent and timely rows that simply never arrived.
- Profiling describes observed data, validation checks reviewed expectations, anomaly detection flags departures, and observability connects signals to response; skipping the first step is what Sambasivan and colleagues found to be “pervasive (92% prevalence), invisible, delayed, but often avoidable”.
- Global statistics stay stable while slices collapse: NISTIR 8280 measured false positive rates that “often vary by factors of 10 to beyond 100 times” across demographics, and Gender Shades measured 34.7% error for darker-skinned females against 0.8% for lighter-skinned males.
- Profiles must cover keys, fields, time, slices, relationships and the target itself — the risk-prediction algorithm dissected in Science had healthy features and a defective target, worth 17.7% against 46.5% of Black patients flagged for extra help.
- Hard thresholds should encode impossible or contract-breaking behaviour rather than observed ranges: every value in the Mars Climate Orbiter's “Small Forces” file was type-valid and in range, and the spacecraft arrived approximately 170 kilometers lower than planned.
- Every anomaly comparison should retain its named reference, method, slice definition and dataset version — Google Flu Trends “missed high for 100 out of 108 weeks starting with August 2011” against the CDC data it was fitted to, and Ofqual refused to model cohorts of fewer than 15 students at all.