Logistic Regression vs Linear Regression

Logistic regression vs linear regression is the comparison every machine learning beginner has to settle early, because the two look almost identical on paper yet solve completely different problems: one predicts a number, the other predicts a probability. This guide lays them side by side — the math, the shapes, worked intuition, and exactly when to use each.

logistic regression vs linear regression comparison of a straight line and an S-shaped sigmoid curve
Linear regression fits a straight line; logistic regression fits an S-shaped probability curve.

Logistic regression vs linear regression at a glance

Both are supervised learning algorithms that fit coefficients to data, but the type of answer they produce is what separates them. Here is the whole comparison in one table:

AspectLinear regressionLogistic regression
PredictsA continuous numberA probability (then a class)
Output range$-\infty$ to $+\infty$$0$ to $1$
Curve shapeStraight lineS-shaped sigmoid
Task typeRegressionClassification
Fitted byLeast squares (minimize error)Maximum likelihood
Example question“How much will this house sell for?”“Is this email spam, yes or no?”
Linear in…the inputsthe log-odds

What is linear regression?

Linear regression predicts a continuous value by fitting a straight line through the data. With one input, the model is simply:

$$\hat{y} = \beta_0 + \beta_1 x$$

where $\beta_0$ is the intercept and $\beta_1$ is the slope. The output $\hat{y}$ can be any real number, so it is perfect for quantities like price, temperature, or weight. The line is chosen by least squares — the coefficients that make the squared gap between predictions and actual values as small as possible. You can fit one yourself with our linear regression calculator.

What is logistic regression?

Logistic regression answers a yes/no question instead of a “how much” question. It takes the same linear combination $z = \beta_0 + \beta_1 x$ but squeezes it through the sigmoid (logistic) function so the result is always a probability between 0 and 1:

$$p = \sigma(z) = \frac{1}{1 + e^{-z}}, \qquad z = \beta_0 + \beta_1 x$$

That $S$-shaped curve never goes below 0 or above 1, which is exactly what a probability needs. To turn the probability into a decision, you apply a threshold — usually predict class 1 when $p \ge 0.5$, which happens precisely when $z \ge 0$. Because it outputs classes, logistic regression is a classification algorithm despite the word “regression” in its name.

Why “regression” if it classifies? The name survives from the math: logistic regression performs a regression on the log-odds. It models a continuous quantity (the log-odds) with a straight line, then maps it to a probability. The regression is real — it just happens one layer down.

The key difference: output and the link function

If you remember only one thing about logistic regression vs linear regression, make it this: they share the same linear core $\beta_0 + \beta_1 x$, but logistic regression wraps it in a link that bounds the output.

Linear regression uses the linear term directly as the prediction. Logistic regression instead sets the linear term equal to the log-odds (the logit) of the event:

$$\ln\!\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1 x$$

This is the answer to a question searchers ask constantly — is logistic regression linear? Yes, but linear in the log-odds, not in the probability. The probability curve itself is non-linear (the sigmoid); the relationship only becomes a straight line once you transform to log-odds.

📊 Reading the coefficientIn linear regression, $\beta_1$ is “how many units $y$ rises per unit of $x$.” In logistic regression, $e^{\beta_1}$ is the odds ratio — how the odds multiply per unit of $x$. Same slope, different interpretation.

When to use linear vs logistic regression

The choice comes straight from your target variable. Ask what you are predicting:

  1. Is the answer a number on a continuous scale? (price, height, sales) → use linear regression.
  2. Is the answer a yes/no or category? (pass/fail, spam/not spam, disease/no disease) → use logistic regression.
  3. Is it a count or a rate? → neither — reach for Poisson or another generalized linear model.
⚠ Don’t use linear regression for classificationIt is tempting to fit a line to 0/1 labels, but linear regression will predict impossible probabilities below 0 and above 1, and it is sensitive to outliers along the decision boundary. The bounded sigmoid of logistic regression is built to avoid exactly this.

The math, side by side

StepLinear regressionLogistic regression
Model$\hat{y}=\beta_0+\beta_1 x$$p=\dfrac{1}{1+e^{-(\beta_0+\beta_1 x)}}$
OutputAny real numberProbability in $(0,1)$
Loss minimizedSum of squared errorsLog loss (cross-entropy)
Fit methodLeast squares / normal equationMaximum likelihood via gradient descent
DecisionUse the value directlyClass 1 if $p \ge 0.5$

Notice the engine underneath is the same: both find coefficients by minimizing a cost function. Linear regression has a neat closed-form solution; logistic regression has no closed form, so it is solved iteratively with gradient descent — the same optimizer used across deep learning.

A worked intuition: predicting exam outcomes

Suppose your input $x$ is hours studied. With linear regression you might predict the exam score ($\hat{y}=40+5x$): study 8 hours, predict 80 marks. With logistic regression you instead predict the probability of passing: as hours rise, $p$ climbs along the sigmoid from near 0, through 0.5 at the threshold, up toward 1. Same single input, but one model outputs a number and the other a probability of a yes/no event — the entire distinction in one example.

What logistic and linear regression have in common

The comparison gets easier once you see how much the two actually share — the differences are a thin layer on top of a common foundation:

  • Both are generalized linear models (GLMs). Each builds a prediction from the same linear term $\beta_0 + \beta_1 x_1 + \dots + \beta_k x_k$; they differ only in the link function applied to that term (identity for linear, logit for logistic).
  • Both are supervised. Each learns from labeled training examples by fitting coefficients that minimize a cost function.
  • Both extend to many inputs. Add more features and the line becomes a plane (linear) or a multi-dimensional decision boundary (logistic) — the algebra barely changes.
  • Both give interpretable coefficients. A larger $|\beta_1|$ means a stronger effect of that feature in either model; only the units of that effect differ.

So the honest summary of logistic regression vs linear regression is not “two unrelated tools” but “one linear backbone, two link functions, two kinds of answer.” That framing is also why logistic regression is usually taught immediately after linear regression — you already know 80% of it.

🤖 ML context

Both sit in the supervised learning family — see our guide on supervised vs unsupervised vs reinforcement learning. Logistic regression is also the simplest neural network: a single neuron with a sigmoid activation. Master this comparison and you have the foundation for classification across all of ML. Build intuition with the regression calculator.

Frequently asked questions

What is the main difference between logistic regression and linear regression?
Linear regression predicts a continuous number with a straight line; logistic regression predicts a probability between 0 and 1 with an S-shaped sigmoid and is used for classification.
Is logistic regression linear?
It is linear in the log-odds, not in the probability. The model sets the log-odds equal to a straight line beta0 + beta1*x, but the probability curve itself is the non-linear sigmoid.
When should I use logistic regression instead of linear regression?
Use logistic regression when the outcome is categorical (yes/no, pass/fail, spam/not spam). Use linear regression when the outcome is a continuous number such as price or temperature.
Why is it called logistic “regression” if it does classification?
Because it performs a regression on the log-odds — it fits a straight line to a continuous quantity (the logit) and then maps that to a probability and a class.
Can I use linear regression for a yes/no problem?
It is not recommended. Linear regression can predict probabilities below 0 or above 1 and is unstable near the boundary. Logistic regression’s bounded sigmoid is designed for this case.

Key takeaways

The logistic regression vs linear regression decision reduces to one question: are you predicting a number or a category? Linear regression fits a straight line for continuous targets; logistic regression wraps the same linear term in a sigmoid to output a probability for classification. They share an engine but answer different questions. Continue with the linear regression calculator, the types of machine learning guide, or the formal reference on Wikipedia.

Scroll to Top