Logistic regression is a model for binary classification. It combines the input features into a linear score, sends that score through the sigmoid function, and produces a number between and that is interpreted, under the fitted model, as the estimated probability of the positive class.
Despite the name, logistic regression is usually used to decide between two classes such as pass/fail, spam/not spam, or default/no default. The word "regression" refers to the linear formula inside the model, not to predicting a continuous output.
Logistic regression formula at a glance
Binary logistic regression uses
with the sigmoid function
The linear part can be any real number. The sigmoid squeezes that value into , which is why the output can be used as a probability estimate.
Why the sigmoid function matters
If you used the raw linear score as a probability, you could get impossible values such as or . The sigmoid fixes that by mapping large negative scores close to , large positive scores close to , and scores near close to .
That gives a practical reading:
- if is very negative, the model leans toward class
- if is near , the model is uncertain
- if is very positive, the model leans toward class
The curve is steepest near . So a small change in the score can change the probability a lot near , but much less when the probability is already close to or .
Worked logistic regression example
Suppose a model uses one feature and has
You can think of as a test score and as "pass." The coefficients here are just an example to show the mechanics.
If , then
So the predicted probability is
If , then
and
So the same model gives about a chance of passing at and about a chance at . The score rose by , but the final output stayed between and because the sigmoid bends the result into a probability.
If you now choose a threshold of , the first case is classified as class and the second as class . That last step depends on the threshold. The probability estimate itself does not.
One useful shortcut: with a threshold, the class flips exactly when , because .
How logistic regression becomes a classifier
The model output is a probability estimate. A classification rule is added afterward.
For example, with threshold :
- predict class if
- predict class if
But is not always the right threshold. If false positives and false negatives have different costs, or if the classes are highly imbalanced, another threshold may work better.
What the coefficients mean
The sign of a coefficient tells you the direction of the effect on the linear score :
- if , increasing raises and tends to increase
- if , increasing lowers and tends to decrease
That part is straightforward. The subtle point is that the probability does not change linearly with the feature, because the sigmoid curve is not a straight line.
In standard logistic regression, the linear model is on the log-odds scale:
This means each one-unit increase in a feature changes the log-odds linearly when the other features are held fixed. That is more precise than saying it changes the probability by a fixed amount.
Common logistic regression mistakes
Treating the output as a guaranteed class
A prediction like does not mean the event will happen. It means the model assigns about a estimated probability to the positive class for that input.
Assuming the threshold must be
is common, but it is a choice, not a law. The best threshold depends on the application.
Thinking the probability changes linearly
The score is linear in the inputs, but the probability is not. A one-unit change in a feature can have a different effect near than near .
Forgetting the model is binary unless extended
Basic logistic regression handles two classes. Multi-class versions exist, but they are extensions, not the same binary setup written in a different way.
When logistic regression is used
Logistic regression is often used when the target is yes/no, such as spam detection, disease presence, customer churn, loan default, or pass/fail outcomes.
It remains popular because it is simple, fast, and reasonably interpretable. It is especially useful when you want a baseline classifier, when the dataset is not huge, or when you need estimated probabilities rather than only hard labels.
A simple way to picture it
Think of logistic regression as a two-step machine:
- Add up evidence with a linear score.
- Convert that score into a probability with the sigmoid.
That picture is enough to understand most introductory examples and to see why logistic regression sits between linear models and classification tasks.
Try a similar logistic regression problem
Pick a simple score such as
Compute for a few values of , such as , , and . Watch how the linear score changes steadily while the probability bends through an S-shaped curve. Then try a different threshold and see when the predicted class changes.
Need help with a problem?
Upload your question and get a verified, step-by-step solution in seconds.
Open GPAI Solver →