Skip to content

Answer key · Question bank 04

Back to the questions


Section A (1 mark each)

A1 — b. Only a test that runs both paths on the same input can detect a divergence. A unit test (a) tests one path; a smoke test (c) tests neither.

A2 — c. Shape and callability are proven; correctness is not. This is the most common weak test in ML code: it asserts that the function ran.

A3 — a. A changing output name changes the stage's identity, so the cache never hits and downstream stages rerun. It does not affect accuracy (c) directly.

A4 — b. Nulls in a required column are a precondition failure. A shifted mean (a) may be genuine drift and belongs in monitoring; (c) is an outcome of training, not an input to it.

Section B (3 marks each)

B1. It produces false confidence and consumes the time that would have gone into a real check. Worse, it legitimises the behaviour: someone reads the green tick as evidence. A test must be able to fail; write it against a deliberately broken input once and watch it go red.

B2. Unit (a calculation, e.g. distance unit conversion); data (schema, nulls, ranges, leakage); model (metric floor, slice behaviour, invariance); integration or contract (API vs training path, pipeline wiring). One mark each, with the defect being one only that layer catches. A model test cannot catch a null column; a data test cannot catch feature skew.

B3. Profile the stages (dvc status, timing per stage); check whether declared dependencies actually changed; look for undeclared inputs or outputs with timestamps; check whether a stage writes to a path outside its outs; check whether the cache directory is on a slow disk or being cleaned each run. Three checks, one mark each.

Section C (4 marks each)

C1. A timestamp with a one-second difference: the code is probably calling now() inside the logic, or formatting with second precision. Make time an explicit input — inject a fixed datetime, or freeze it (freezegun or a monkeypatched clock) — and assert on the formatted value. Two marks for the diagnosis, two for the fix that removes the clock from the unit under test.

C2. Reasons and checks:

Reason Check
The gate compares against a baseline regenerated by the same run Pin the baseline and assert its hash
The gate reads a metric from the wrong file or key, defaults to pass Print the value read; test the gate with a deliberately bad metric
The gate is skipped by a path filter or continue-on-error Inspect the workflow run's steps, not just the badge
The gate metric is computed on the training set Recompute on the held-out split and compare

Accept any three. Full marks require the check, not only the suspicion.

Section D (9 marks)

Element Marks What it looks like
Unit tests 1 Pure transforms, boundary values, deterministic
Data tests 2 Schema, nulls, ranges, duplicate applications, row-count bounds, and a rule that stops the run on failure
Model tests 2 Metric floor on a fixed holdout, slice checks for protected groups, invariance to irrelevant fields
Integration/contract 2 Scoring path matches training features; database write is idempotent for a given application ID; a dry run against a test table
Failure handling 1 Non-zero exit, no partial writes, an alert with the failing check and row count
What is not automated 1 Fairness decisions, threshold changes, and anything requiring a human judgement about applicants; these are reviewed, with the evidence prepared automatically

A strong answer says the run must not write partial results, and distinguishes a data failure (stop) from a drift warning (continue and report). A plan that automates the lending decision itself, rather than the checks around it, loses the judgement mark.