Logistic Regression
Logistic Regression — Predict class probabilities with an S-shaped curve.
Despite the name, logistic regression is for classification. It squashes a linear score through an S-shaped sigmoid to output a probability between 0 and 1, then draws a decision boundary.
- Class 0
- Class 1
- Boundary (p=0.5)
Logistic controls
The idea in plain words
Despite the name, logistic regression classifies. It takes the same linear score as linear regression and squashes it through an S-shaped sigmoid into a probability between 0 and 1. The boundary is where that probability crosses 0.5.
Drag a point and the whole probability field re-forms. If the classes are perfectly separable the fit keeps pushing the weights larger and larger to make the sigmoid ever steeper — a runaway you can trigger by pulling the clusters apart.
Now, the math
The probability of the positive class is a sigmoid of the linear score:
- the sigmoid — squashes any score into (0, 1).
- the linear score; where it is 0 the probability is 0.5.
▸ Show the derivation
Logistic regression minimizes the cross-entropy (log) loss by gradient descent. On separable data that loss has no finite minimum — pushing ‖w‖ toward infinity drives every predicted probability to 0 or 1, so the weights never settle. Regularization (as in ridge) is what tames it in practice.
Trace it by hand
Take one point x = (1.0, 1.0) with weights w = (0.5, 0.3) and bias b = 0. We push its linear score through the sigmoid to get a probability. Values rounded to 4 decimal places.
Compute the linear score
Squash it through the sigmoid
e to the minus 0.8 is 0.4493, so the denominator is 1.4493.
Read off the decision
Check a point on the other side
A negative score always lands below probability 0.5 — the boundary is exactly where the score is 0.
What just happened: A score of plus 0.8 became probability 0.69 and a score of minus 0.5 became 0.38 — the sigmoid maps the signed distance from the boundary into a confidence, and the 0.5 cutoff is the score-zero line.
Now Break It
Try this: On non-linearly-separable data, no straight boundary can separate the classes — errors are unavoidable.
Control: Switch dataset to XOR / concentric pattern
What happens: Not linearly separable! No straight line can split these classes — logistic regression is fundamentally limited here.
Where logistic regression is used
Logistic regression is one of the most widely deployed classifiers in industry precisely because it is fast, interpretable, and outputs calibrated probabilities. Banks use it for credit scoring, where each coefficient shows how much a factor like income or existing debt shifts the odds of default. Hospitals use it to estimate the probability that a patient has a condition given lab values, and epidemiologists rely on it to quantify how a risk factor changes disease likelihood. Email spam filters, click-through-rate prediction in online advertising, and A/B test analysis all lean on the same S-shaped model. Its popularity endures because a trained logistic regression can be inspected, audited, and explained to a regulator far more easily than a deep network.
A frequent misconception is that logistic regression performs regression in the usual sense. It is a classification method: it models the probability of a class using the logistic (sigmoid) function, then a threshold turns that probability into a label. Another pitfall is assuming the decision boundary can be curved. Logistic regression draws a linear boundary in the feature space you give it, so genuinely non-linear patterns need engineered features or interaction terms. People also misread the coefficients as effects on probability, when they are actually effects on the log-odds; the same coefficient shifts probability by different amounts depending on where you are on the curve. Finally, the default 0.5 threshold is a convention, not a law, and should be tuned to the costs of each error type.
Frequently asked questions
Why is it called regression if it does classification?
What does the sigmoid function actually do here?
How do I interpret the coefficients?
Can logistic regression handle more than two classes?
Does logistic regression need feature scaling?
Written & reviewed by the ML Visualization team · Last updated .