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 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:
| Aspect | Linear regression | Logistic regression |
|---|---|---|
| Predicts | A continuous number | A probability (then a class) |
| Output range | $-\infty$ to $+\infty$ | $0$ to $1$ |
| Curve shape | Straight line | S-shaped sigmoid |
| Task type | Regression | Classification |
| Fitted by | Least squares (minimize error) | Maximum likelihood |
| Example question | “How much will this house sell for?” | “Is this email spam, yes or no?” |
| Linear in… | the inputs | the 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.
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.
When to use linear vs logistic regression
The choice comes straight from your target variable. Ask what you are predicting:
- Is the answer a number on a continuous scale? (price, height, sales) → use linear regression.
- Is the answer a yes/no or category? (pass/fail, spam/not spam, disease/no disease) → use logistic regression.
- Is it a count or a rate? → neither — reach for Poisson or another generalized linear model.
The math, side by side
| Step | Linear regression | Logistic regression |
|---|---|---|
| Model | $\hat{y}=\beta_0+\beta_1 x$ | $p=\dfrac{1}{1+e^{-(\beta_0+\beta_1 x)}}$ |
| Output | Any real number | Probability in $(0,1)$ |
| Loss minimized | Sum of squared errors | Log loss (cross-entropy) |
| Fit method | Least squares / normal equation | Maximum likelihood via gradient descent |
| Decision | Use the value directly | Class 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?
Is logistic regression linear?
When should I use logistic regression instead of linear regression?
Why is it called logistic “regression” if it does classification?
Can I use linear regression for a yes/no problem?
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.