Classification with Regression
Don't let the name fool you β Logistic Regression is a classification algorithm, not a regression one. It's used when the output is a category (like yes/no, spam/not spam, cat/dog) rather than a continuous number. It's one of the most widely used algorithms for binary classification.
The Sigmoid Function
Logistic Regression uses the sigmoid function to squash any input into a value between 0 and 1. This output can be interpreted as a probability.
Sigmoid Function: Ο(z) = 1 / (1 + e^(-z))
Output
1.0 β€ βββββββββ
β βββ
0.8 β€ ββ
β ββ
0.6 β€ ββ
β ββ
0.5 β€β β β β β ββββ β β β β Decision boundary
β ββ
0.4 β€ ββ
β ββ
0.2 β€ ββ
β βββ
0.0 β€βββββββββ
βββββββββββββββββββββββββββββββββββ Input (z)
-6 -4 -2 0 2 4 6
Output β₯ 0.5 β Class 1 (e.g., "spam")
Output < 0.5 β Class 0 (e.g., "not spam")
How It Works
- Take the weighted sum of inputs (like linear regression)
- Pass it through the sigmoid function
- If the output β₯ 0.5, predict class 1; otherwise, predict class 0
- Use cross-entropy loss to measure error
- Update weights using gradient descent to minimize loss
Logistic Regression vs Linear Regression
Linear Regression: Logistic Regression:
βββββββββββββββββββ βββββββββββββββββββ
β Input βββΊ Output β β Input βββΊ 0 or 1 β
β (continuous) β β (probability) β
β β β β
β Best for: β β Best for: β
β Predicting priceβ β Predicting classβ
β Predicting temp β β Spam detection β
β Forecasting β β Disease diagnosisβ
βββββββββββββββββββ βββββββββββββββββββ
Multi-Class Extension
While vanilla logistic regression is binary, it can be extended to multi-class problems using One-vs-Rest (OvR) or Softmax regression (also called Multinomial Logistic Regression). Softmax outputs a probability distribution across all classes.
Why It's Still Popular
Logistic Regression is fast, interpretable, and gives you probabilities, not just hard classifications. It's often the first algorithm to try for any classification problem and serves as a baseline for comparing more complex models.