Risk-based testing for ML systems
Why This Matters
There is always more to test than time to test it. Risk-based testing decides where the effort goes: to what is most likely to go wrong and would hurt most if it did. For ML systems this is not optional: most AI regulation, including the EU AI Act, demands a risk-based approach. And the risks are partly new ones, so you need a way to find them.
What you will learn
- How risk-based testing applies to ML systems
- The three risk categories along the ML workflow: development, input data and model
- How to build a risk table for an ML system and derive the test focus from it
Syllabus: AI-4.3.2.
Risk-based testing, briefly
A risk is something that may go wrong, with a likelihood and an impact. Risk-based testing identifies the risks, rates them, and lets the rating decide what to test, how thoroughly, and in which order. High likelihood and high impact gets the most testing.
This applies to every system. For ML systems two things are different: regulators expect it (the EU AI Act requires a risk management system for high-risk AI, lesson 4), and the list of what can go wrong is longer.
Three categories along the workflow
The syllabus groups ML risks by where they arise in the ML workflow:
| Category | Examples of risks | Covered in |
|---|---|---|
| Development | Sub-optimal algorithm choice; a poor model-development process; a framework with security vulnerabilities. Mostly project risks. | Module 8 |
| Input data | Biased data; unrepresentative data; poisoned data; defects in the data pipeline | Module 6 |
| Model | Not meeting the performance criteria; overfitting; susceptibility to adversarial examples | Module 7 |
Each later module starts with a table of risks and the test approach that mitigates each one. This lesson is about using such tables.
An alternative way to find risks: go through the quality characteristics of ISO/IEC 25059 (lesson 6) and ask, for each one, what could go wrong here. What if it cannot explain a decision (transparency)? What if an operator cannot stop it (intervenability)? What if it fails on noisy input (robustness)? This catches risks that a workflow view misses, such as missing human oversight.
A worked risk table: a fraud-detection model
A bank flags card transactions as possibly fraudulent. Flagged transactions are blocked until the customer confirms them.
| # | Risk | Category | Likelihood | Impact | Level | Test focus |
|---|---|---|---|---|---|---|
| 1 | Fraud patterns change; the model misses new types of fraud | Model (drift) | High | High | High | Drift testing on weekly labelled samples; alert threshold on recall (lesson 47) |
| 2 | Too many legitimate transactions blocked, customers leave | Model (performance) | Medium | High | High | Precision on a representative test set, per customer segment; acceptance criteria with confidence levels (lesson 44) |
| 3 | Training data contains few transactions from abroad; travellers are blocked more often | Input data (representativeness) | Medium | Medium | Medium | Compare the training distribution with production; precision per country (lesson 37) |
| 4 | Fraud labels are wrong (disputed transactions marked as fraud) | Input data (labels) | Medium | Medium | Medium | Label review on a sample with multiple annotators (lesson 39) |
| 5 | Model flags customers of certain nationalities or ages more often | Input data / model (bias) | Medium | High | High | Disparate impact analysis with counterfactual pairs (lesson 35) |
| 6 | Fraudsters learn to split payments just below a pattern | Model (adversarial) | Medium | High | High | Adversarial testing around the decision boundary (lesson 45) |
| 7 | Feature pipeline in production calculates “transactions in the last hour” differently than in training | Input data (pipeline) | Low | High | Medium | Back-to-back test of the training and production pipeline (lesson 36) |
| 8 | Wrong data split: transactions of one customer in training and test | Development | Low | Medium | Low | Review of the data allocation (lesson 51) |
How to read it:
- Four risks are high (1, 2, 5, 6). They get the most effort, are tested first, and their tests run on every model version.
- Every risk has a test approach that fits it: drift needs monitoring, bias needs counterfactual testing, adversarial risk needs adversarial testing. A generic “run the regression suite” mitigates none of them well.
- Some risks are only testable after release (1, partly 3). The risk table is also a monitoring plan.
- The ratings are judgements, made with the business, data scientists and, for 5, legal. Writing them down makes them discussable.
Exercise
A hospital uses a model that predicts which emergency-department patients should be seen first (triage). Build a risk table with at least five risks: at least one from each category (development, input data, model), with likelihood, impact and test focus. Which risk would you test first?
Show suggested answer
| # | Risk | Category | L | I | Test focus |
|---|---|---|---|---|---|
| 1 | Seriously ill patients are given low priority (false negatives) | Model | Medium | Very high | Recall on the “urgent” class, with a high confidence level; boundary testing around the priority threshold |
| 2 | Training data comes from one hospital; patient mix elsewhere differs | Input data | High | High | Representativeness testing against the target hospital’s patient data; performance per subgroup |
| 3 | Model under-prioritises women or older patients because historic triage did | Input data | Medium | Very high | Testing for bias: performance and priority per group; counterfactual pairs |
| 4 | Labels (historic triage decisions) are inconsistent between nurses | Input data | High | High | Multiple annotation of a sample by experienced nurses; inter-annotator agreement |
| 5 | Missing vital signs make the model fail or give a default priority | Model | Medium | High | Robustness testing with missing and invalid values; output boundaries |
| 6 | The model version deployed is not the one validated | Development | Low | Very high | Configuration management review; smoke test of the deployed version |
| 7 | Nurses cannot override the priority quickly | System (controllability) | Low | Very high | Usability and controllability test of the override |
Test risk 1 first: patient harm is the highest impact, and it is the core function. Risks 3 and 7 are close: risk 3 is the one that regulators and patients will ask about, and 7 is cheap to test and decisive for safety.
Exam-style questions
1. Which is an example of an input data risk for an ML system?
- A. Overfitting
- B. Poisoned training data
- C. Sub-optimal algorithm selection
- D. Susceptibility to adversarial examples
Show answer
2. Besides the ML workflow categories, how else can risks for an ML system be categorised?
- A. By the quality characteristics of ISO/IEC 25059
- B. By the number of lines of code
- C. By the programming language
- D. Only by test level
Show answer
3. Why is risk-based testing particularly expected for AI-based systems?
- A. AI-based systems cannot be tested in any other way
- B. Most AI regulatory frameworks require a risk-based approach
- C. Risk-based testing is only used for AI
- D. It removes the need for acceptance criteria