Data quality and provenance
Data quality means fitness for a specified task: are records complete enough, accurate enough and representative enough to support the intended prediction? Provenance documents where data came from and what happened to it. Before training, inspect both. In an inventory table, zero units is a valid count; an unknown count is not zero. A model cannot recover the original value merely because we replaced a missing entry.
Distinguish missing values from observed zero
The fictional shop has three stock records: 12 units, an unknown count, and 0 units. Represent unknown values using Python None, which is distinct from the integer 0. is None tests whether the value is the special None object. We assume each record has the opening_stock key and its value is either a nonnegative integer or None. A missing key would violate this schema; validate it separately rather than silently interpreting it as a known zero.
def stock_summary(records): missing = 0 known = 0 total = 0 for record in records: value = record["opening_stock"] if value is None: missing += 1 else: known += 1 total += value return [known, missing, total]
records = [ {"opening_stock": 12}, {"opening_stock": None}, {"opening_stock": 0},]print(stock_summary(records))print(stock_summary([]))print(stock_summary([{"opening_stock": None}]))The result is [known count, missing count, sum of known values]. Two observations are known, one is missing, and the known sum is 12. The mean of the known values is 12 / 2 = 6. Replacing missing with zero would instead produce 12 / 3 = 4, an unsupported claim about stock. The empty dataset has no observations. The all-missing dataset has one unknown observation, so neither has a meaningful observed mean. The sum of zero known values is zero by convention, not proof that stock is zero.
Separate invalid values, noise and duplicates
An invalid value violates an explicit contract, such as -3 units in this nonnegative stock field. Noise is measurement variation or error; a plausible integer can still be wrong. An outlier is unusual relative to other values and may be valid. Do not remove a rare high-stock record solely because it is unusual. A duplicate occurs when the same intended sample identity appears more than once; identical feature values on different days are not necessarily duplicates. In the next example, sample IDs are required strings, and each should occur only once.
def find_stock_issues(records): issues = [] seen = [] for record in records: key = record["sample_id"] stock = record["opening_stock"] if key in seen: issues.append([key, "duplicate sample ID"]) else: seen.append(key) if stock is None: issues.append([key, "missing stock"]) elif type(stock) is not int or stock < 0: issues.append([key, "invalid stock"]) return issues
records = [ {"sample_id": "A", "opening_stock": 12}, {"sample_id": "B", "opening_stock": None}, {"sample_id": "A", "opening_stock": -3}, {"sample_id": "C", "opening_stock": 0},]for issue in find_stock_issues(records): print(issue[0], issue[1])The audit returns a list of issues without editing the source records. type(stock) is not int rejects non-integer values, including Python booleans, which are not valid stock counts in our schema. or short-circuits, so a string is not compared numerically to zero. One record can have multiple issues. The repeated sample ID requires investigation: it may be a duplicate, a correction, or evidence that the ID scheme is wrong. Do not guess which record is authoritative.
Investigate why information is missing
Missing counts may arise from a failed scanner, an unavailable feed or a busy worker skipping entries. If missing records occur more often on busy days, deleting them may distort the dataset. Imputation means supplying an estimated value; it requires a justified policy and should be distinguishable from observations. Possible responses include recovering the source, excluding affected records with documented impact, using a missingness indicator, or deferring prediction. There is no universal missing-data fix.
Record provenance and sampling boundaries
For every dataset, document origin, collection period, population, sample unit, field meanings and units, permitted uses, license or consent where applicable, transformations, missing-value conventions, dataset version and limitations. For the three-record fixture: origin is original synthetic ByteMind examples; no real people or stores; no actual collection dates; one intended sample per product-day; stock is units; unknown is None; fixture version 1; no transformations or real-world representativeness claims. No external dataset license or consent is needed for this invented non-personal fixture. This does not establish rights for future datasets.
Representativeness depends on the intended use. If the shop records only weekdays, a weekend forecast has little direct support. Selection bias is systematic distortion from how observations enter the dataset. High accuracy on weekday-only data does not establish weekend accuracy. Compare coverage across relevant categories and periods, examine how labels were recorded, and document what cannot be measured. Label errors require their own review: valid-looking values may still be incorrect.
Practice and recap
For [0, None, 5], the known count is 2, the missing count is 1, and the known sum is 5. Explain why the missing value should not be converted into a zero without evidence. In a separate dataset, identify repeated sample IDs and one out-of-range observation, then write an audit note rather than overwriting the raw records. The chapter project combines a prediction-time feature contract, data quality audit and provenance note. Next: vectors and matrix shapes, which provide a common representation for numerical features.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Data quality and provenance — understanding check
Apply data literacy concepts to original synthetic inventory examples.
What is the known count in [12, None, 0]?
Why does replacing None with zero change the mean of [12, None, 0]?
Two valid records share a stock count but have distinct product-day IDs. What should the audit conclude?
Which information best supports a stock dataset provenance audit?
A dataset contains weekdays only. What can its weekday results establish about weekend performance?