ML development risks and mitigations
Why This Matters
Not every ML defect lives in the data or the model. The framework can have a bug in its evaluation code, the data split can leak, the deployment build can change the model, the hyperparameters can be chosen badly. These are risks in how the model was built and shipped, and they are tested with familiar tools: reviews, smoke tests, API tests, A/B and back-to-back testing.
What you will learn
- The risks that come from ML development tools, configuration choices and deployment
- Which test approach mitigates each
- Where you have already met these risks in this course
Syllabus: AI-7.1.1.
Development risks and mitigations
ML development testing focuses on the tools, configuration choices and deployment mechanisms, not on the model itself.
| Development risk | Test approach | Where you saw it |
|---|---|---|
| Incorrect use of a library or framework API | API testing | |
| Sub-optimal framework selection | Framework suitability review | lesson 3 |
| Unfairness introduced by the algorithm or framework | Testing for bias | lesson 35 |
| Defective installation or build | Smoke testing | lesson 52 |
| Defective evaluation code in the framework | Review the evaluation code; cross-check against manual benchmarks | lesson 19: the library’s metrics checked against the formulas |
| Slow framework | Performance testing | |
| Poor framework usability | Usability testing | |
| A defect in a framework library, or a defective algorithm implementation | ML functional performance testing, back-to-back testing | lessons 44, 49 |
| Security issues in the framework | Security testing | |
| Poor framework documentation | Documentation review | |
| Sub-optimal algorithm selection | Algorithm suitability review, A/B testing | lesson 20 |
| Sub-optimal hyperparameters (network structure, learning rate) | ML functional performance testing, A/B testing | lessons 16, 48 |
| Defective split into training, validation and test data | Data allocation review | lesson 16: duplicates in both sets |
| Poor evaluation approach (for example how k-fold cross-validation is set up) | ML functional performance testing | lesson 16 |
| Misreading results because of stochastic learning | ML functional performance testing | lessons 26, 44 |
| A deployment defect from generating a platform-specific version | Smoke testing, ML functional performance testing, A/B testing | lesson 52 |
| Model incompatible with the operational environment | Smoke testing, MLS deployment testing | lesson 52 |
| The new model is no better than the current one | Shadow testing | lesson 52 |
Three worth a closer look
Defective evaluation code. Every number you report comes from evaluation code: yours or the framework’s. If precision and recall are swapped (lesson 19 showed how easily that happens with confusion_matrix(...).ravel()), every decision based on them is wrong. Cross-check the library’s output against a manual calculation on a small example.
Misreading stochastic results. Training involves randomness: random starting weights, random data shuffling, random splits. Train the same model twice and the scores differ. A team that runs one training of model A and one of model B and picks the higher score may be choosing noise. Repeat training runs, or fix the random seeds and report the spread.
Data allocation. Records of the same customer, or duplicates, in both training and test data make test results too optimistic (lesson 16). A review of how the data was split, and a test like test_test_data_is_independent, catches it.
Exercise
Match each situation to a development risk and a test approach.
- A team cannot reproduce last month’s model: retraining on the “same” data gives 3 points lower accuracy.
- After converting a model for a mobile app, it crashes on older phones.
- Two data scientists each ran one training of their candidate model and chose the one with 0.5% higher accuracy.
- The test score is 98%, but the test data contains transactions from the same customers as the training data.
Show suggested answer
- Possibly stochastic learning or unversioned data/configuration. Approaches: ML functional performance testing with repeated runs and fixed seeds; a configuration management review of data and code versions (lesson 36).
- Model incompatible with the operational environment / deployment defect: smoke testing and MLS deployment testing on the target devices (cross-device testing, lesson 52).
- Misreading results because of stochastic learning: repeat the training several times and compare the distributions (ML functional performance testing), or an A/B test with a significance test.
- Defective data split: data allocation review; split by customer, not by transaction.
Exam-style questions
1. Which test approach mitigates the risk that a newly trained model is no better than the model in production?
- A. Installability testing
- B. Shadow testing
- C. Label correctness testing
- D. Neuron coverage
Show answer
2. A framework’s built-in function for calculating recall might be defective. What is the recommended mitigation?
- A. Use a different programming language
- B. Review the evaluation code and cross-check the results against manual benchmarks
- C. Stop calculating recall
- D. Increase the training data