A batch of spam-classifier records just came off the extractor,
headed for a training set. Write validate_batch(records) — the
boundary in one function. Return two lists, (clean, flagged). A
record is flagged if any check fails:
- a
REQUIREDfield is missing (use thenot incomprehension), - its
labelis not inLABELS, - its
confidenceis outside 0.0-1.0.
Check for missing fields first — the other checks index into keys that might not exist. The bottom of the starter prints the counts, then the label and confidence of each clean record.
Expected output:
2 3
spam 0.98
ham 0.91