Skip to main content

Test levels for ML systems

Why This Matters

“We tested the model” is not “we tested the system”. A model with 95% accuracy in a notebook can be fed the wrong columns by the pipeline, get its predictions mangled by the user interface, or lose accuracy when it is compressed for production. ML systems need two extra test levels, and all the familiar ones still apply.

What you will learn

  • The two ML-specific test levels: input data testing and ML model testing
  • What component, integration, system, system integration and acceptance testing mean for an ML system
  • How to map tests of a real ML system to the right level

Syllabus: AI-4.3.1.

Two levels added

  • Input data testing (module 6): testing the data, both the training data and the production data the model receives in operation. Constraints, bias, representativeness, labels, the pipeline.
  • ML model testing (module 7): testing the model, the end product of the ML workflow. Functional performance, robustness, overfitting, drift, metamorphic and adversarial testing.

The conventional levels still apply

An ML model is one component of a system. Around it are user interfaces, data pipelines, databases, APIs and other services.

LevelWhat it covers in an ML system
Component testingNon-model components: the user interface, the data pipeline components, communication components
Component integration testingData flowing into the model correctly (right features, right order, right format) and predictions flowing out to the UI correctly. When the model is used as a service (AI as a Service), API testing belongs here.
System testingDoes the model’s performance survive being embedded in the system? Especially after deliberate changes such as compressing a DNN for production. Non-functional tests such as prediction latency.
System integration testingInterfaces with external systems, in an environment representative of production: the data sources, the CRM that receives the scores, monitoring tools
Acceptance testingIs the AI service suitable for the users? Are the ML functional performance criteria met (lesson 8)?

Two failures that only higher levels catch:

  • The model expects income in euros; the pipeline sends it in cents. Every component passes its own tests. Component integration testing catches it, if someone checks that features arrive in the agreed units.
  • The model was 94% accurate; after quantization for the production server it is 89%. Model testing in the notebook passed. System testing on the deployed system catches it.

Mapping tests to levels: the practice loan system

The tests you wrote in this course already cover several levels:

Test in your practice projectLevel
module-6/test_dataset_constraints.pyInput data testing
module-3/test_data_preparation.pyComponent testing (of the data pipeline) and input data testing
module-3/test_splits.pyInput data testing (dataset allocation)
module-4/test_evaluate_model.pyML model testing
module-7/test_metamorphic.pyML model testing, through the API
setup/test_setup.py (API reachable, answers valid)Component integration testing (API)
The bias lab: entering an applicant in the web form and seeing the decisionSystem testing

What is missing? There is no system integration testing (nothing receives the bank’s decisions), and no acceptance testing with real loan officers. In a real project those would be on the plan.

Exercise

A webshop adds a model that recommends products on the product page. Name one test for each level: input data, model, component, component integration, system, system integration and acceptance.

Show suggested answer
  • Input data: the click and purchase history used for training has no duplicate orders, and covers all product categories.
  • Model: precision of the top-5 recommendations on a held-out month of purchases is at least the agreed threshold.
  • Component: the recommendation widget in the UI shows 5 products, handles an empty list, and shows the right images.
  • Component integration: the product page sends the right product ID and user ID to the recommendation service, and the returned IDs exist in the catalogue (API testing).
  • System: the whole page loads within 1 second with recommendations, under expected load; recommendations are still relevant after the model was converted for the production server.
  • System integration: recommendations exclude products the stock system reports as sold out; clicks reach the analytics system.
  • Acceptance: in a pilot with real users, the click-through rate and the conversion meet the agreed criteria.

Exam-style questions

Quiz

1. A team uses an AI service from a cloud provider through its API. At which test level does testing of this API belong?

  • A. Input data testing
  • B. Component integration testing
  • C. Acceptance testing
  • D. ML model testing
Show answer
B.
Quiz

2. A deep neural network is compressed to run faster in production. At which level is it confirmed that its performance survived the compression in the embedded system?

  • A. Component testing
  • B. System testing
  • C. Input data testing
  • D. Acceptance testing only
Show answer
B.
Quiz

3. Which two test levels are specific to ML systems?

  • A. Component testing and system testing
  • B. Input data testing and ML model testing
  • C. Acceptance testing and system integration testing
  • D. API testing and performance testing
Show answer
B.