Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 06 / Topic 4 of 7

Choosing a threshold

predict uses 0.5 by default. The right threshold comes from the use case, and the probabilities let you choose:

# examples/03_moving_the_decision_threshold_trades_precision.py (abridged)
print("threshold  precision  recall")
for t in [0.3, 0.5, 0.7]:
    pred = (proba >= t).astype(int)
    print(f"   {t:.1f}       {precision_score(y_te, pred):.3f}    {recall_score(y_te, pred):.3f}")
# threshold precision recall
#    0.3 0.536 0.742
#    0.5 0.633 0.475
#    0.7 0.889 0.200

Lowering the threshold catches more churners (recall 0.742) but wastes more calls (precision 0.536). Raising it makes almost every flag real (precision 0.889), but you catch only one churner in five. A retention team that can call 100 customers a month picks the threshold that fills exactly that capacity with the highest-probability cases — that is this part's mini-project.

🧪 Quick quiz

  1. Lowering the threshold from 0.5 to 0.3 usually does what?
Show the answer

Raises recall and lowers precision — measured above: 0.3 gave precision 0.536 / recall 0.742 vs 0.633 / 0.475 at 0.5.

Done here? The practice set for Part 6 — 4 exercises with solutions — is on the part page.

Search the guide