Input data risks and mitigations
Why This Matters
A model learns what its data teaches it, including the mistakes. Biased data gives a biased model; mislabelled data gives a model that confidently repeats the mislabelling; data that does not look like production gives a model that fails in production. Most of these defects cannot be seen in the model at all. They have to be found in the data, which is why input data testing is a test level of its own.
What you will learn
- What input data testing covers: training, test and prediction data, and the pipeline
- The main input data risks, and the test approach that mitigates each
- How the lessons in this module fit together
Syllabus: AI-5.1.1.
What input data testing is
Input data testing confirms that the data used to train, test and make predictions with an ML system is of sufficient quality. It covers all three:
- training data: what the model learns from
- test data: what the model is judged on
- prediction data: what the model receives in production
Methods range from reviews (of the data and its documentation) to statistical techniques, exploratory data analysis (EDA), and static and dynamic testing of the data pipeline.
Risks and the approaches that mitigate them
| Risk | Example | Test approach | Lesson |
|---|---|---|---|
| Biased training data, or unfairness introduced by the algorithm | Historic loan decisions disadvantaged women | Testing for bias | 35 |
| Untrustworthy sources, poor data management | Data bought from an unknown broker; nobody knows which version was used | Data provenance testing: where does the data come from, who changed it, is it the version we think? | 36 |
| Poisoned data | An attacker plants examples so that a certain input is always approved | A/B testing, data provenance testing, EDA, red-teaming attacks | 49, 36, 29 |
| Internally inconsistent data, out-of-range values, wrong types | Age 150, income −5,000, “thirty-five” in a number column | Dataset constraint testing | 38 |
| Sub-optimal feature selection | A feature that leaks the answer, or a key feature left out | Feature testing: does each feature contribute, is any of them a proxy for a sensitive attribute or for the label? | 35, 16 |
| Imbalanced or skewed data, missing data, narrow coverage | Training data from five cities, production from ten | Data representativeness testing | 37 |
| Poor labels, ambiguity, inconsistent annotation | Two annotators label the same scan differently | Label correctness testing | 39 |
| Pipeline design, quality, performance or security problems | Production computes a feature differently from training | Data pipeline testing | 36 |
Three risks deserve a closer look:
Poisoned data is deliberate. An attacker who can influence the training data (through user feedback, scraped web pages, a compromised supplier) can teach the model a backdoor: a trigger that makes it give the attacker’s answer. It is hard to spot, because the rest of the model behaves normally. Provenance (only trusted sources), EDA (unusual clusters), comparing models trained with and without suspicious data (A/B), and attacking it yourself (red teaming) are the defences.
Feature selection is easy to overlook. A feature can encode the answer by accident (“account closed date” in a churn model) or encode a sensitive attribute indirectly: the zip code in the practice loan model is a proxy for income and ethnicity (lesson 46, exercise 1). Feature testing checks what each feature contributes and what it might stand in for.
Representativeness is about the whole dataset, not single records. Every record can be correct while the set as a whole describes a different population than the one the model will serve.
This module in practice
You have already tested the practice loan data in several ways. The rest of the module completes the picture:
the loan data
├─ constraints per record and per column lesson 38 (done) test_dataset_constraints.py
├─ bias: does a sensitive attribute matter? lesson 35 test_bias.py
├─ pipeline: is it processed the same way? lesson 36
├─ representativeness: train vs production lesson 37 test_representativeness.py
├─ labels: are the answers right? lesson 39 test_label_correctness.py
└─ missing, duplicates, outliers: a report lesson 40 test_input_data.py
Exercise
Match each risk to the test approach that mitigates it best.
- A face recognition model was trained on photos that are 80% of light-skinned people.
- 3% of the training records have a date of birth in the future.
- Medical images were labelled by students; some labels are wrong.
- A competitor submitted thousands of fake reviews to a sentiment model’s feedback loop.
- The feature “number of complaints” is calculated per month in training and per week in production.
Show suggested answer
- Data representativeness testing (and testing for bias: the skew will show up as worse performance for darker-skinned people).
- Dataset constraint testing (a range constraint on the date).
- Label correctness testing (expert review of a sample, multiple annotation).
- Poisoned data: data provenance testing (where does feedback come from?), EDA (an unusual burst of reviews), A/B testing (compare a model trained with and without the suspicious data).
- Data pipeline testing: back-to-back testing of the training and production pipeline.
Exam-style questions
1. Which test approach mitigates the risk of poisoned training data?
- A. Dataset constraint testing only
- B. Data provenance testing, EDA, A/B testing and red-teaming attacks
- C. Label correctness testing only
- D. Performance testing
Show answer
2. Training data contains far fewer examples of one class than of the other. Which test approach addresses this?
- A. Data representativeness testing
- B. Data pipeline testing
- C. API testing
- D. Back-to-back testing