Skip to main content

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

RiskExampleTest approachLesson
Biased training data, or unfairness introduced by the algorithmHistoric loan decisions disadvantaged womenTesting for bias35
Untrustworthy sources, poor data managementData bought from an unknown broker; nobody knows which version was usedData provenance testing: where does the data come from, who changed it, is it the version we think?36
Poisoned dataAn attacker plants examples so that a certain input is always approvedA/B testing, data provenance testing, EDA, red-teaming attacks49, 36, 29
Internally inconsistent data, out-of-range values, wrong typesAge 150, income −5,000, “thirty-five” in a number columnDataset constraint testing38
Sub-optimal feature selectionA feature that leaks the answer, or a key feature left outFeature 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 coverageTraining data from five cities, production from tenData representativeness testing37
Poor labels, ambiguity, inconsistent annotationTwo annotators label the same scan differentlyLabel correctness testing39
Pipeline design, quality, performance or security problemsProduction computes a feature differently from trainingData pipeline testing36

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.

  1. A face recognition model was trained on photos that are 80% of light-skinned people.
  2. 3% of the training records have a date of birth in the future.
  3. Medical images were labelled by students; some labels are wrong.
  4. A competitor submitted thousands of fake reviews to a sentiment model’s feedback loop.
  5. The feature “number of complaints” is calculated per month in training and per week in production.
Show suggested answer
  1. Data representativeness testing (and testing for bias: the skew will show up as worse performance for darker-skinned people).
  2. Dataset constraint testing (a range constraint on the date).
  3. Label correctness testing (expert review of a sample, multiple annotation).
  4. 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).
  5. Data pipeline testing: back-to-back testing of the training and production pipeline.

Exam-style questions

Quiz

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
B.
Quiz

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
Show answer
A. Imbalanced or skewed data is a representativeness risk.