Skip to content

Logistic Regression (Binary vs Multiclass)

Why it’s called β€œregression”

Logistic regression is a classification algorithm.

It models a probability using a logistic (sigmoid) function.

Binary logistic regression

It predicts:

  • probability of class 1, p = P(y=1|X)p = P(y=1|X)

Then:

  • predict 1 if p >= thresholdp >= threshold else 0

false


  flowchart LR
  Z[Linear score z = wΒ·x + b] --> S[Sigmoid]
  S --> P[p = probability]
  P --> Y[Class via threshold]

false

The sigmoid intuition

  • large positive z β†’ p close to 1
  • large negative z β†’ p close to 0

Multiclass logistic regression

Common approaches:

  • One-vs-Rest (OvR): train one classifier per class
  • Softmax (multinomial): one model for all classes

Scikit-learn can do both.

Scikit-learn example

LogisticRegression (binary or multiclass)
from sklearn.linear_model import LogisticRegression
 
# For multiclass, common choice:
clf = LogisticRegression(max_iter=1000, multi_class="auto")
LogisticRegression (binary or multiclass)
from sklearn.linear_model import LogisticRegression
 
# For multiclass, common choice:
clf = LogisticRegression(max_iter=1000, multi_class="auto")

Threshold tuning matters

Default threshold is 0.5, but for imbalanced problems you may choose:

  • lower threshold to increase recall
  • higher threshold to increase precision

Mini-checkpoint

If missing fraud is expensive, do you optimize for precision or recall?

(Usually recall.)

πŸ§ͺ Try It Yourself

Exercise 1 – Train-Test Split

Exercise 2 – Fit a Linear Model

Exercise 3 – Evaluate with MSE

If this helped you, consider buying me a coffee β˜•

Buy me a coffee

Was this page helpful?

Let us know how we did