Page 3 of 8~104 min topic

Prediction: your first ML idea

Run the working guess path

Page 3 is the clean arcade run: five rounds, one cutoff, guesses and a scoreboard you can check by hand.

~13 min this pageImplementation

1Learn the idea

Read

Build only the shortest working path

You are not shipping an app store product. You are proving: for this fixture and this threshold, guesses and confusion counts are exact. Prefer boring, readable Python over a mysterious library you cannot explain to a friend.

Run the path twice. Matching output both times is a feature — like a basketball drill that lands the same way when form is steady.

Read

The working path

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

Trace one round like a replay

Take score 0.8 with truth 1. Score ≥ 0.5 → guess 1. Pair (1, 1) is a true positive (correct yes) — like calling “make” when the ball really went in.

Take score 0.3 with truth 0. Guess 0. Pair (0, 0) is a true negative (correct no).

On this fixture every guess matches: three true positives, two true negatives, zero false alarms, zero misses. Accuracy is (3 + 2) / 5 = 1.00.

School metaphor: TP is correctly spotting a spam text; FP is wrongly accusing a normal text; TN is correctly leaving a normal text alone; FN is missing a real spam text.

Read

Intermediates worth printing

While you run, make sure you can narrate:

  1. Each score compared to the threshold.
  2. The preds list.
  3. The four bucket counts and accuracy.

If you can only say “it printed something,” you do not yet own the happy path.

Go deeper

Before you start

Why this matters

Without running code, walk five free-throw clues: scores 0.8, 0.3, 0.6, 0.9, 0.2 with threshold 0.5. Which rounds become “will go in” (1)? Which become “miss” (0)? Write your predicted preds list, then name one intermediate you would print to prove you are not guessing from vibes.

Check your understanding

Page assessment

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

1. Can you narrate every line from score → guess → bucket?
2. Did two runs on the same fixture match?
3. Do you still refuse to claim this works for every phone?
4. Can a friend recompute accuracy with a calculator?

All responses are required.