Measure quality with explicit rules and denominators
Combine row constraints, NULL semantics, profiling, and sampling boundaries before accepting a training-data quality percentage.
On this page
The question for today
What you’ll understand
- Define validity as an explicit predicate with null and range behavior.
- Choose denominators that retain missing and rejected records when required.
- Distinguish a profile estimate from exhaustive enforcement and source completeness.
A dashboard says that 97 percent of feature values are valid, yet a model sees many missing examples. The number may describe only non-null values or only rows that survived an earlier filter. Quality measurement begins by defining the population and the failure rules, then choosing a denominator that matches the question. A familiar SQL expression is not automatically the intended policy, especially when NULL, duplicates, sampling, and upstream omissions change what is counted.
Turn a quality claim into a predicate
For a score intended to lie between zero and one, decide whether missing values are allowed, how non-finite values are handled, and whether values outside the interval are rejected or quarantined. A row can satisfy the type schema while violating this application rule. In PostgreSQL, an ordinary CHECK passes when its expression is true or unknown, so a range comparison alone does not necessarily reject NULL. Add the appropriate not-null requirement when absence is invalid. Other engines and validators have their own semantics; write representative cases and inspect the actual evaluated result rather than assuming a Boolean expression has identical behavior everywhere.
Record-level predicates do not express every quality obligation. Uniqueness spans a defined key scope, referential integrity relates datasets, and an expected row count depends on which source events should exist. A foreign key can establish a referenced identifier exists without proving that the associated training label is correct. Likewise, a nonempty string constraint does not establish that a text example is useful or permitted for training. Classify each rule by what it proves, who owns its definition, and which operation enforces it. Keep exceptions versioned rather than changing the interpretation of failure after inspecting an inconvenient batch.
Count the population you claim to assess
COUNT(*) counts rows, whereas COUNT(column) ignores null values in familiar SQL aggregate semantics. Dividing valid non-null scores by the latter measures quality among present values, not among all submitted rows. Both metrics can be useful if labeled correctly. Also retain counts before and after parsing, filtering, deduplication, and quarantine. A perfect profile of the surviving rows can conceal that a large share never reached the profiler. Expose the admission funnel so an apparent improvement caused by dropping difficult examples cannot be mistaken for a repaired source.
When several rules fail on the same row, adding their individual failure counts can overcount rejected rows. Use a union of failed-row identities for total rejection and separate per-rule counts for diagnosis. The intersection matters, particularly when a broken parse creates several downstream missing fields. Define duplicate handling before comparing counts: an example repeated three times contributes differently to row count, distinct-key count, and a weighted training distribution. Quality metrics should make these differences visible instead of compressing every issue into one percentage whose numerator and denominator change between reports.
A profile is evidence with a scope
A profile can reveal value ranges, missingness, categories, and shifts, but it does not automatically enforce the rule on future writes. Sampling reduces cost while potentially missing rare or localized defects; sampling only one partition or only successful parses can also bias the result. Check important slices such as collection source, language, ingestion hour, and label class, and preserve the profile's source snapshot and selection procedure. A training-quality change can reflect a genuine population shift rather than a broken pipeline, so compare data provenance and the intended population before deciding which values should be repaired.
The sampling instrument shows an exact distribution under a known independent Bernoulli model. For each comparison, Reset, set both p=0.1 and n to 20 or 100, predict the sample-mean variance, then inspect. The respective variances are 0.0045 and 0.0009. Playback highlights possible outcomes rather than collecting samples. This does not turn a convenience sample into representative data or guarantee discovery of a defect confined to an unobserved partition. Its normal comparison is an approximation with explicit limits, while the exact binomial distribution still relies on independent observations with a common probability.
Work it through
Separate present-value quality from submitted-row quality
A submitted batch has 1000 rows:20 missing scores, 30 present scores outside[0, 1], and 950 present in-range scores. The missing and out-of-range groups are disjoint. Calculate two useful valid fractions.
COUNT(*) over the submitted batch is 1000, while COUNT(score) is 980 because the 20 missing scores are excluded from that aggregate.
Using all submitted rows, the valid fraction is 950/1000=95%. The 50 invalid rows include both missing and out-of-range cases.
Among present scores, the valid fraction is 950/980≈96.94%. Label that denominator explicitly; reporting it as quality of all submitted rows would conceal missingness.
Both 95% and 96.94% can be correct for different questions. The dashboard must state the assessed population rather than let NULL semantics choose it accidentally.
The living notebook
Explore the model
Interactive lab · sampling
A larger representative sample narrows one kind of uncertainty
For each view: Reset, set both p=0.1 and n, predict, then inspect. Compare n=20 with n=100. Exact binomial masses describe a hypothetical independent defect indicator’s sample mean; no random sample is being generated and no dataset is scanned.
- Mean sample proportion
- 0.5
- Sample-mean variance
- 0.0125
- Uniform CDF error bound
- ≤ 0.1062
Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forSample-mean variance falls from 0.0045 to 0.0009. More observations do not repair selection bias, omitted rows, or a rule that treats NULL differently from the intended contract.
Pause & reason
Check your understanding
Your turn
Try it yourself
In a100-row batch, 10 rows fail rule A and 15 fail rule B;4 fail both. How many rows fail at least one rule, and what fraction pass both?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use the union formula before subtracting from the fixed 100-row population.
Compare with the solution
The union has 10+15−4=21 rows, leaving 79 that pass both, or 79%. Adding failures without subtracting the overlap would incorrectly count 25 rejected rows.
Keep the idea
Take it with you
- Quality rules need explicit population, NULL, unit, and failure semantics.
- Denominators and overlapping failures change the meaning of percentages.
- Profiles and samples reveal evidence within their captured scope; enforcement and completeness need more.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.