Labs ICT
⭐ Pro Login

Logistic Regression

Classification using the sigmoid curve.

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

  1. Take the weighted sum of inputs (like linear regression)
  2. Pass it through the sigmoid function
  3. If the output β‰₯ 0.5, predict class 1; otherwise, predict class 0
  4. Use cross-entropy loss to measure error
  5. 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.

πŸ§ͺ Quick Quiz

What activation function is commonly used in Logistic Regression?