Build garagePlay → read → next · ~9 min

Tutorials · Chapter D (4/4) · ~9 min

Prediction: your first ML idea

Play → read → next

Tune a tiny predictor and watch accuracy go up — a win you can demo live.

Playground

Prediction: your first ML idea

Tune a tiny rule-based “model.” Watch accuracy change.

100% accuracy
  • Mom: dinner at 7

    Pred: not spam · Truth: not spam ·

  • URGENT!!! click now to WIN money

    Pred: spam · Truth: spam ·

  • School homework reminder

    Pred: not spam · Truth: not spam ·

  • FREE FREE FREE act immediately!!!

    Pred: spam · Truth: spam ·

Recap

What you just did

You built the ML loop in miniature: predict → score → adjust. You didn’t train a deep net yet — you felt the idea that “learning” means your rule gets better on measured examples. Point at the accuracy number: “I changed the threshold; that went up.”

Teach

How it works

A tiny predictor is often a threshold on a score:

truth = [1, 0, 1, 1, 0]
scores = [0.8, 0.3, 0.6, 0.9, 0.2]
threshold = 0.5

preds = [1 if s >= threshold else 0 for s in scores]
accuracy = sum(p == t for p, t in zip(preds, truth)) / len(truth)
  1. Features / scores — what the model “sees”
  2. Label — the correct answer for each row
  3. Rule — e.g. “score ≥ threshold → yes”
  4. Accuracy — fraction of matches

Mental model: ML is practicing on past quizzes, then taking a new quiz.

Use it

When you'd use this

  • Deciding spam vs not from a spamminess score
  • Approving a loan only above a risk cutoff
  • Tuning “how sure” you need to be before auto-acting

Watch out

Watch out

High accuracy on a tiny toy set can fool you. One lucky threshold that memorizes ten examples may fail on the eleventh. Always ask: “Would this hold on new rows?”

Try next

Try this next

Slide the threshold higher, then lower. Note one setting where accuracy drops. That’s evidence you’re really steering the rule.