Page 2 of 8~104 min topic

Prediction: your first ML idea

Set the rules of the guess lists

A fair mini game needs clear rules for what may enter the scoreboard — before anyone argues about who “won.”

~13 min this pageData contract

1Learn the idea

Read

The contract for this game

Think of the code as a board game with three piles:

  1. Truth pile — only 0 or 1 for each round (did the shot go in? was it spam?).
  2. Score pile — numbers between 0 and 1 (how strong the clue looked).
  3. Threshold — one cutoff, also between 0 and 1.

Same length for truth and scores. No secret third list. No pasting real classmate messages into the demo — use made-up practice rounds.

If a score is out of range or the piles do not line up, that is a rules bug, not proof that “the AI is dumb.” Fix the rules before you trust the scoreboard.

Read

Same working path, rules angle

We still run the happy fixture so you can see a clean contract in action:

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

Read

Why this setup counts as a contract

  • Every score sits in [0, 1], and so does threshold.
  • truth and scores both have length 5, so zip pairs them honestly.
  • Guesses are only 0 or 1, never a mystery third label.
  • The printout names predictions and the four buckets, so nobody can hide behind a lonely accuracy number.

Write a one-line rule for each field: required shape, allowed range, and what is forbidden (real phone numbers, real chat logs, scores above 1).

Read

Separate “check the lists” from “count the scoreboard”

First make sure the piles are legal. Only then count TP/FP/TN/FN. Mixing those jobs makes debugging feel like random blame: Was the threshold wrong, or did someone paste six scores and five truths?

Go deeper

Before you start

Why this matters

You are writing the rule card taped to the classroom Chromebook: what lists are allowed, what a score must look like, and what the threshold means. Invent one broken input a classmate might type by accident (a score of 1.7, a threshold of -2, or a truth list longer than the scores list). Predict what should happen: a clear “nope,” not a silent wrong answer.

Check your understanding

Page assessment

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

1. Which fields are required, and what ranges do they allow?
2. What happens if truth and scores have different lengths?
3. Did you ban real classmate messages from the demo data?
4. Can you tell a rules bug apart from a wrong guess?

All responses are required.