Skip to content

Logistic Regression

Despite its name, a classifier: it turns a weighted sum of features into a probability between 0 and 1 using the S-shaped sigmoid curve.

Also logit model

Fig. / How it works
0.5
Role · kind
Models and algorithmsModel
Level
Beginner

Cox, 1958

It is a yes/no machine that also says how sure it is. Feed it clues about a customer and it says 'leaving: 80% sure'.

Where it fits

+All relationships as a list

See it on the full map

How it works

Logistic regression starts like linear regression: a weighted sum of features. But a sum can be any number, and we want a probability. So the sum goes through the sigmoid, an S-shaped curve that maps very negative numbers to almost 0, very positive ones to almost 1, and 0 to exactly 0.5.

To make a decision, pick a threshold (often 0.5): above it is “yes”, below is “no”. All the points where the probability is exactly 0.5 form the decision boundary, which is always a straight line (or flat plane).

Training cannot use squared error well here; instead it uses cross-entropy, which punishes confident wrong answers hard. There is no closed-form solution, so the weights are found with gradient descent or a similar optimizer.

The mathP(y=1∣x)=σ(w⊤x+b),σ(z)=11+e−zP(y = 1 \mid x) = \sigma(w^\top x + b), \qquad \sigma(z) = \frac{1}{1 + e^{-z}}

Taking logs of the odds shows why it is a linear model:

log⁡P(y=1∣x)1−P(y=1∣x)=w⊤x+b\log \frac{P(y=1 \mid x)}{1 - P(y=1 \mid x)} = w^\top x + b

Everyday use cases

  • Case 01

    Customer churn

    Will this subscriber cancel next month? Yes or no, with a probability the sales team can rank by.

  • Case 02

    Credit default risk

    Banks have used logistic regression for decades because regulators can read the weights.

  • Case 03

    Click prediction

    Will a user click this ad? Fast enough to score billions of ads a day.

Famous examples

Strengths, weaknesses and when to use it

Strengths

  • Outputs calibrated-ish probabilities, not just a label.
  • Fast, stable and interpretable (weights are log-odds).

Weaknesses

  • Linear decision boundary: cannot separate classes that need a curved border without feature engineering.

When to use itFor binary classification where you need probabilities and explainability, and as a baseline for any classifier.

Compare with

Check yourself

  1. Q01

    What kind of task is logistic regression used for?

    Show answer

    B: Classification

  2. Q02

    What does the sigmoid function do?

    Show answer

    A: Squashes any number into the range 0 to 1

Go deeper