← AI / ML Foundations
6 / 25
Lesson 6 — Sigmoid: choosing a threshold
From probability to a decision
A probability alone does not act. To make a decision (spam / not spam) we pick a threshold: if the probability is at least the threshold, we say "yes". The default is 0.5, but you can move it. A higher threshold means fewer "yes" answers, and each one is more certain.
p = 0.7
print("spam" if p >= 0.5 else "ok") # spam
Why it matters: for a spam filter, wrongly blocking a real email is worse than letting one spam through — so real systems often raise the threshold. Choosing it is a product decision, not just maths.
Want it another way?
Task
Finish flagged(probs, threshold) so it counts probabilities >= threshold. Expected: 3 flagged at 0.5, 1 at 0.9.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.