ML (Beginner) · Core Models · cozy lesson
Classification Intuition
11 min · 2 min read · no scary math, promise
Sorting things into buckets
Spam or ham? Churn or loyal? Malignant or benign? Whenever the answer is a category, you're classifying. The workhorse starter is logistic regression — a confusing name for a clean idea: model the probability of each class, then pick the highest. Despite "regression" in the name, it outputs categories.
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report
model = LogisticRegression(max_iter=1000).fit(Xtr, ytr)
print(classification_report(yte, model.predict(Xte)))
Accuracy is a liar (when classes imbalance)
A fraud detector facing 99% legitimate transactions scores 99% accuracy by predicting "legit" always — perfect score, worthless model. The honest report card:
- Precision: of the flagged ones, how many were real? (False alarms cost trust.)
- Recall: of the real ones, how many did we catch? (Misses cost money/lives.)
- F1: their harmonic mean — one number that refuses to be gamed by imbalance.
Always report these for the rare class you actually care about — the fraud, the churners, the diagnoses.
Thresholds are business decisions
Models output probabilities; you choose the cutoff. Flag fraud above 0.3 if missing fraud is expensive; require 0.9 if false alarms wake people at night. Moving the threshold trades precision against recall — a product decision wearing math clothes, and interviewers love asking about it.
Remember this
- Categories out → classification. Imbalanced data → precision/recall/F1, never raw accuracy.
- Thresholds encode business costs; choose them deliberately, not by default 0.5.
Check your understanding
Correct answers earn XP (once each).
1. Accuracy lies when…
2. Logistic regression is…
My notes (saved in this browser)
Select text above → Save selection, or write your own. Your notebook lives in this browser.
No notes yet. Your highlights will live here.
Finished reading? Seal it with a tick ✅
The checkbox in the explorer turns green too — same progress.