Page 5 of 8~104 min topic

Prediction: your first ML idea

Treat bad lists like game bugs

When the mini game breaks, reproduce the bug on purpose — empty lists and mismatched lengths are stage hazards, not mysteries.

~13 min this pageDebugging

1Learn the idea

Read

Failure modes for this toy

Common game bugs:

  1. Empty lists — no rounds to score; accuracy would divide by zero.
  2. Mismatched lengthszip silently stops at the shorter list, so leftover truths or scores vanish.
  3. Threshold outside 0..1 — a cutoff of 1.5 means almost nothing ever counts as a yes.
  4. Reporting accuracy alone — hides whether you got false alarms or misses.

These are input and rules bugs. Fix them before you accuse the guessing logic of being “random.”

Read

Keep the healthy path as your control

Always keep one known-good run so you can tell “still broken” from “fixed”:

truth = [1, 0, 1, 1, 0]
scores = [0.8, 0.3, 0.6, 0.9, 0.2]
threshold = 0.5
preds = [int(score >= threshold) for score in scores]

pairs = list(zip(truth, preds))
tp = pairs.count((1, 1)); fp = pairs.count((0, 1))
tn = pairs.count((0, 0)); fn = pairs.count((1, 0))
accuracy = (tp + tn) / len(pairs)
print(preds, f"accuracy={accuracy:.2f}", tp, fp, tn, fn)

Expected evidence:

[1, 0, 1, 1, 0] accuracy=1.00 3 0 2 0

If your “bug fix” changes this healthy output, you broke the working path while chasing a failure.

Read

Reproduce on command

In your notes, store a tiny mutant:

  • truth = [] or scores = [] → refuse to compute accuracy.
  • truth length 5, scores length 4 → refuse or warn before zip hides a round.
  • threshold = 1.5 → reject as out of range.

Paste the failing message into failure-before.txt. After you add a guard, paste failure-after.txt. Retries do not help a bad list — retrying empty input just fails again.

Read

Repair with a reviewable change

A good fix is small and readable: check lengths, check ranges, then run the scoreboard. After repair, rerun the healthy fixture and confirm the expected evidence line still appears.

Go deeper

Before you start

Why this matters

Picture a classroom arcade cabinet. Someone starts a round with no scores, or pastes six truths and five scores. The screen should not quietly invent answers. Write the bug name you expect (“empty list” or “length mismatch”) and what a helpful error would say in plain kid words.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Can you force empty-list and length-mismatch failures on demand?
2. Did you keep the healthy expected line as a regression check?
3. Is the error about rules/input, not vague “AI failed”?
4. Would a friend know which bug you fixed from your before/after notes?

All responses are required.