MACHINE LEARNING / 2. LOGISTIC REGRESSION
Logistic Regression
Classification via probability — not actually regression
EXPLANATION
Despite the name, logistic regression is a classification algorithm. It predicts the probability that a sample belongs to a class. The key: wrap linear regression output in a sigmoid function to squash it to (0, 1): p = σ(Xw + b) = 1 / (1 + e^-(Xw+b)) Training minimizes Binary Cross-Entropy (Log Loss): L = -[y·log(p) + (1-y)·log(1-p)] Decision boundary: predict class 1 if p >= 0.5, else class 0. For multi-class: • One-vs-Rest (OvR) → train N binary classifiers • Softmax (multinomial) → generalize sigmoid to K classes Why logistic regression is still relevant: • Interpretable (coefficients = feature importances) • Fast to train and predict • Works well on linearly separable data • Great baseline before trying complex models • Used in ad click prediction at massive scale
DATA FLOW
Linear output z = Xw + b (any real number)
↓
Sigmoid: p = 1/(1+e^-z) (squashed to 0-1)
↓
Decision: class = 1 if p >= 0.5
Sigmoid curve:
1.0 | ──────────
| ──/
0.5 | ──/
| ──/
0.0 |──
└──────────────────── z
0
Log loss penalizes confident wrong predictions heavilyCODE