Linear Regression and the Least Squares Objective

Suppose a hospital wants to predict a patient's blood pressure. It uses age, weight, and sodium intake as inputs. The relationship is unlikely to be perfectly linear. Still, a straight-line approximation is often good enough. It is easy to fit and easy to interpret. Linear regression formalizes this instinct. It assumes the target is a weighted sum of the inputs plus noise. Then it chooses weights that make predictions match observed data as closely as possible. This idea sits at the foundation of statistical modeling and machine learning. It is the first algorithm most practitioners learn. Yet it powers real systems: econometric forecasting, A/B test analysis, risk scoring. It also appears in the last layer of many neural networks. It drives control systems that need fast, interpretable predictions. Its popularity comes from a rare combination. It has a convex objective with a closed-form solution. It has strong statistical theory. And its predictions can be explained in one sentence ("each extra kilogram adds 0.4 mmHg"). The big picture is this: pick a hypothesis class (linear functions). Pick a loss that measures prediction error (squared error). Then find the parameters that minimize total loss over training data. This "model + loss + optimizer" template is the scaffolding. It supports essentially all of supervised learning. This ranges from linear regression to deep neural networks. Linear regression is the cleanest possible instance of that template. That is exactly why it is worth mastering deeply. It should not be treated as a footnote. This article defines the linear model and the least-squares objective precisely. It derives why squared error is a natural choice. It works through the geometry and calculus of the loss surface. It also traces a full numerical example by hand. It sets up — without yet solving — two standard ways to find optimal weights. One is an exact formula: the normal equations. The other is an iterative method: gradient descent. Both are covered in their own articles.

Key takeaways
  • Linear regression models a target as y≈w⊤x+by \approx w^\top x + b, a weighted sum of features plus a bias.
  • The least-squares objective is the mean (or sum) of squared residuals between predictions and true values.
  • Squared error is not arbitrary: it falls out of assuming Gaussian noise and maximizing likelihood.
  • The loss is a convex quadratic bowl in weight space, guaranteeing a unique global minimum (generically).
  • Fitting means minimizing this bowl — done exactly via the Normal Equations or iteratively via Gradient Descent.
  • The framework generalizes directly to Ridge Regression (add a penalty) and Logistic Regression (change the link function).
The core insight

Linear regression finds the weights that minimize total squared prediction error, which is equivalent to finding the maximum-likelihood fit under Gaussian noise.

The idea

A linear model predicts a scalar target y∈Ry \in \mathbb{R} from a feature vector x∈Rdx \in \mathbb{R}^d as

y^=w⊤x+b=∑j=1dwjxj+b,\hat{y} = w^\top x + b = \sum_{j=1}^{d} w_j x_j + b,

where w∈Rdw \in \mathbb{R}^d is the weight vector and b∈Rb \in \mathbb{R} is the bias (or intercept). It is common to absorb the bias into ww by appending a constant feature x0=1x_0 = 1 to every input, giving the compact form y^=w⊤x\hat{y} = w^\top x with w,x∈Rd+1w, x \in \mathbb{R}^{d+1}. The model is called linear because y^\hat{y} is a linear (affine) function of the parameters ww — not necessarily of the raw inputs, since features can include polynomials, logs, or interactions of the original variables. Given a training set {(x(i),y(i))}i=1n\{(x^{(i)}, y^{(i)})\}_{i=1}^n, the natural way to judge a candidate ww is to look at the residuals ri=y(i)−y^(i)=y(i)−w⊤x(i)r_i = y^{(i)} - \hat{y}^{(i)} = y^{(i)} - w^\top x^{(i)}. The least-squares objective (also called the sum of squared errors, SSE, or residual sum of squares, RSS) is

J(w)=∑i=1n(y(i)−w⊤x(i))2.J(w) = \sum_{i=1}^{n} \big(y^{(i)} - w^\top x^{(i)}\big)^2 .

Dividing by nn gives the mean squared error (MSE), which is scale-independent across dataset sizes and is the version most often reported and optimized in practice:

J(w)=1n∑i=1n(y(i)−w⊤x(i))2.J(w) = \frac{1}{n}\sum_{i=1}^{n} \big(y^{(i)} - w^\top x^{(i)}\big)^2 .

Fitting the model means solving

w⋆=arg⁡min⁡wJ(w).w^{\star} = \arg\min_{w} J(w).

Why squares, rather than absolute residuals or some other penalty? Two independent reasons converge on the same answer. Geometrically, minimizing the sum of squared residuals is equivalent to finding the orthogonal projection of the target vector y∈Rny \in \mathbb{R}^n onto the subspace spanned by the feature columns — the unique point in that subspace closest to yy in Euclidean distance, which makes squared error the natural companion to linear algebra. Statistically, if we assume y(i)=w⊤x(i)+εiy^{(i)} = w^\top x^{(i)} + \varepsilon_i with independent noise εi∼N(0,σ2)\varepsilon_i \sim \mathcal{N}(0, \sigma^2), the likelihood of the data is

p(y∣X,w)=∏i=1n12πσ2exp⁡ ⁣(−(y(i)−w⊤x(i))22σ2).p(y \mid X, w) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}} \exp\!\left(-\frac{(y^{(i)} - w^\top x^{(i)})^2}{2\sigma^2}\right).

Taking the log and dropping constants that don't depend on ww, maximizing the log-likelihood is exactly the same as minimizing ∑i(y(i)−w⊤x(i))2\sum_i (y^{(i)} - w^\top x^{(i)})^2. So least squares is the maximum-likelihood estimator under Gaussian noise — not an ad hoc choice but the loss implied by the simplest and most common noise assumption.

How it works

Fitting a linear regression model has three conceptual steps: represent the data as matrices, write down the loss as a function of ww, and minimize it. The minimization itself can be done in closed form or iteratively; this article treats the setup and the shape of the objective, while the actual solvers are developed in their own right in The Normal Equations and Closed-Form Solution and Gradient Descent for Parameter Estimation. Stack the nn feature vectors (each with a leading 1 for the bias) into a design matrix X∈Rn×(d+1)X \in \mathbb{R}^{n \times (d+1)}, and stack the targets into y∈Rny \in \mathbb{R}^n. The predictions for the whole dataset are y^=Xw\hat{y} = Xw, and the least-squares objective becomes

J(w)=∥y−Xw∥22=(y−Xw)⊤(y−Xw).J(w) = \|y - Xw\|_2^2 = (y - Xw)^\top (y - Xw).

This is a quadratic function of ww. Expanding it,

J(w)=y⊤y−2w⊤X⊤y+w⊤X⊤Xw,J(w) = y^\top y - 2 w^\top X^\top y + w^\top X^\top X w,

which is a sum of a constant, a linear term in ww, and a quadratic term with matrix X⊤XX^\top X. Because X⊤XX^\top X is positive semi-definite (it equals A⊤AA^\top A for some AA, and v⊤X⊤Xv=∥Xv∥2≥0v^\top X^\top X v = \|Xv\|^2 \ge 0 for all vv), JJ is a convex function of ww: its graph is a bowl, possibly with a flat direction but never a saddle or a local bump. This convexity is the single most important structural fact about linear regression — it is what guarantees that "find the minimum" is a well-posed, solvable problem rather than a search over an unpredictable landscape. To find the minimizer, take the gradient of JJ with respect to ww and set it to zero:

∇wJ(w)=−2X⊤y+2X⊤Xw=0⟹X⊤X w=X⊤y.\nabla_w J(w) = -2 X^\top y + 2 X^\top X w = 0 \quad\Longrightarrow\quad X^\top X \, w = X^\top y.

These are the normal equations; when X⊤XX^\top X is invertible, w⋆=(X⊤X)−1X⊤yw^\star = (X^\top X)^{-1} X^\top y solves the problem exactly in one step. When X⊤XX^\top X is singular or the data is very large, iterative methods like gradient descent are preferred instead. Both routes are explored in depth in their dedicated articles — the point here is that the objective itself, being a convex quadratic, is what makes both routes work. ``` ALGORITHM FitLinearRegressionBySSE(X, y) Input: X, an n x d matrix of feature rows (bias column optionally prepended) y, a length-n vector of targets Output: w, the least-squares weight vector 1. Augment X with a column of ones -> X' (n x (d+1)), unless already done 2. Define J(w) = (y - X' w)^T (y - X' w) # the objective to minimize 3. Solve for the stationary point of J: gradient(w) = -2 X'^T y + 2 X'^T X' w set gradient(w) = 0 ==> X'^T X' w = X'^T y # normal equations 4. If X'^T X' is invertible: w <- (X'^T X')^{-1} X'^T y # closed form, see Normal Equations article else: w <- solve via gradient descent or pseudo-inverse # see Gradient Descent article 5. return w ``` ``` ALGORITHM PredictAndEvaluate(w, X_new, y_new) Input: fitted weights w, new feature matrix X_new, true targets y_new (for evaluation) Output: predictions, and MSE 1. y_hat <- X_new w 2. residuals <- y_new - y_hat 3. MSE <- (1/n) sum(residuals[i]^2 for i in 1..n) 4. return y_hat, MSE ```

Figure
The least-squares fit as an orthogonal projection, and the loss surface it minimizes
1. Data and fitted line x y dashed = residuals rᵢ = yᵢ − ŷᵢ red line = fitted ŷ = wᵀx + b 2. Convex loss surface J(w) w* (minimum) contours of J(w) = ‖y − Xw‖² bowl-shaped ⇒ single global min start

Complexity & correctness

Objective construction. Building the design matrix XX costs O(nd)O(nd) to lay out; computing X⊤XX^\top X costs O(nd2)O(nd^2) multiply-adds (each of the d×dd \times d entries is an inner product over nn rows), and X⊤yX^\top y costs O(nd)O(nd). Evaluating the loss J(w)J(w) for a given ww costs O(nd)O(nd) — one pass over the data to compute residuals and square them.

Solving for ww depends on the chosen method:

  • Closed form via the normal equations requires inverting (or factorizing) the (d+1)×(d+1)(d+1) \times (d+1) matrix X⊤XX^\top X, which costs O(d3)O(d^3) using standard Gaussian elimination or Cholesky decomposition, on top of the O(nd2)O(nd^2) to form X⊤XX^\top X. Total: O(nd2+d3)O(nd^2 + d^3). This is efficient when dd is small to moderate (up to a few thousand) even for very large nn, since the cost grows only linearly in nn.
  • Iterative solvers (gradient descent) cost O(nd)O(nd) per iteration and typically run for TT iterations, giving O(Tnd)O(Tnd) total — attractive when dd is huge or X⊤XX^\top X is ill-conditioned or too large to form explicitly.

Space. Storing XX costs O(nd)O(nd); storing X⊤XX^\top X costs O(d2)O(d^2), independent of nn, which is why the normal-equation route scales gracefully to huge nn as long as dd stays modest.

Correctness — why minimizing JJ is the right thing to do. The argument has two independent legs. Geometric leg. The set of vectors reachable as XwXw for some ww is exactly the column space of XX, a subspace C(X)⊆Rn\mathcal{C}(X) \subseteq \mathbb{R}^n. Minimizing ∥y−Xw∥2\|y - Xw\|^2 over all ww is minimizing distance from yy to a point in C(X)\mathcal{C}(X). Basic Euclidean geometry says the closest point in a subspace to an external point is its orthogonal projection, and the residual vector y−Xw⋆y - Xw^\star at that closest point must be perpendicular to every vector in the subspace — in particular perpendicular to every column of XX:

X⊤(y−Xw⋆)=0⟺X⊤Xw⋆=X⊤y,X^\top (y - Xw^\star) = 0 \quad\Longleftrightarrow\quad X^\top X w^\star = X^\top y,

which is precisely the normal equations derived from calculus above. The two derivations (orthogonality and vanishing gradient) agreeing is not a coincidence — the same minimum has both a geometric and a calculus certificate. Convexity leg. J(w)=w⊤(X⊤X)w−2w⊤X⊤y+y⊤yJ(w) = w^\top(X^\top X)w - 2 w^\top X^\top y + y^\top y has Hessian ∇w2J=2X⊤X\nabla^2_w J = 2 X^\top X, which is positive semi-definite for any XX (shown above). A twice-differentiable function with PSD Hessian everywhere is convex, and for a convex function any stationary point (where the gradient vanishes) is a global minimum, not merely a local one. If X⊤XX^\top X is strictly positive definite (full column rank, i.e., d+1≤nd+1 \le n and no exact linear dependencies among features), the minimum is additionally unique. If X⊤XX^\top X is singular (more features than independent data directions, or collinear features), infinitely many ww achieve the same minimal loss, and regularization — see Ridge Regression and L2 Regularization — is used to pick out one well-behaved solution.

Honest tradeoffs. Squared error weights large residuals quadratically, so a single wild outlier can dominate the fit far more than it should — the least-squares line can be dragged noticeably toward one bad point. Squared error also implicitly assumes a symmetric, Gaussian-shaped noise process; if the true noise is heavy-tailed or skewed, the maximum-likelihood justification for least squares no longer holds, and alternatives like least-absolute-deviations (L1 loss) or robust regression are more appropriate. Linear regression is also, by construction, blind to nonlinear relationships in the raw features — it fits a linear function of whatever features you give it, so nonlinearity in the true relationship must be captured by feature engineering (polynomial terms, interactions) rather than by the model itself.

Worked example

Consider predicting exam score yy from hours studied xx, using four students, and fit a model y^=w1x+w0\hat{y} = w_1 x + w_0 (one feature plus bias).

StudentHours (xx)Score (yy)
A152
B263
C375
D590

Build the design matrix (bias column first) and target vector:

X=[11121315],y=[52637590].X = \begin{bmatrix} 1 & 1 \\ 1 & 2 \\ 1 & 3 \\ 1 & 5 \end{bmatrix}, \qquad y = \begin{bmatrix} 52 \\ 63 \\ 75 \\ 90 \end{bmatrix}.

Step 1 — form X⊤XX^\top X and X⊤yX^\top y.

X⊤X=[4111139],X⊤y=[280862].X^\top X = \begin{bmatrix} 4 & 11 \\ 11 & 39 \end{bmatrix}, \qquad X^\top y = \begin{bmatrix} 280 \\ 862 \end{bmatrix}.

(Check: the (1,1) entry of X⊤XX^\top X is n=4n = 4; the (1,2) entry is ∑xi=1+2+3+5=11\sum x_i = 1+2+3+5=11; the (2,2) entry is ∑xi2=1+4+9+25=39\sum x_i^2 = 1+4+9+25=39. And ∑yi=52+63+75+90=280\sum y_i = 52+63+75+90=280; ∑xiyi=52+126+225+450=853\sum x_i y_i = 52+126+225+450 = 853 — let's recompute carefully: 1⋅52=521\cdot52=52, 2⋅63=1262\cdot63=126, 3⋅75=2253\cdot75=225, 5⋅90=4505\cdot90=450; sum =52+126+225+450=853=52+126+225+450=853. So X⊤y=[280853]X^\top y = \begin{bmatrix}280\\853\end{bmatrix}.)

Step 2 — solve the normal equations X⊤X w=X⊤yX^\top X\, w = X^\top y:

[4111139][w0w1]=[280853].\begin{bmatrix} 4 & 11 \\ 11 & 39 \end{bmatrix} \begin{bmatrix} w_0 \\ w_1 \end{bmatrix} = \begin{bmatrix} 280 \\ 853 \end{bmatrix}.

Determinant of X⊤XX^\top X: 4⋅39−11⋅11=156−121=354 \cdot 39 - 11 \cdot 11 = 156 - 121 = 35. Inverse: 135[39−11−114]\dfrac{1}{35}\begin{bmatrix} 39 & -11 \\ -11 & 4 \end{bmatrix}.

[w0w1]=135[39−11−114][280853]=135[39⋅280−11⋅853−11⋅280+4⋅853].\begin{bmatrix} w_0 \\ w_1 \end{bmatrix} = \frac{1}{35}\begin{bmatrix} 39 & -11 \\ -11 & 4 \end{bmatrix}\begin{bmatrix} 280 \\ 853 \end{bmatrix} = \frac{1}{35}\begin{bmatrix} 39\cdot280 - 11\cdot853 \\ -11\cdot280 + 4\cdot853 \end{bmatrix}.

Compute each entry: 39×280=1092039 \times 280 = 10920; 11×853=938311 \times 853 = 9383; so w0w_0 numerator =10920−9383=1537= 10920 - 9383 = 1537, giving w0=1537/35≈43.914w_0 = 1537/35 \approx 43.914. −11×280=−3080-11 \times 280 = -3080; 4×853=34124 \times 853 = 3412; so w1w_1 numerator =−3080+3412=332= -3080 + 3412 = 332, giving w1=332/35≈9.486w_1 = 332/35 \approx 9.486. So the fitted model is approximately

y^≈9.486 x+43.914.\hat{y} \approx 9.486\, x + 43.914.

Step 3 — check residuals and the loss.

Studentxxyyy^=9.486x+43.914\hat{y} = 9.486x + 43.914residual r=y−y^r=y-\hat yr2r^2
A15253.40−1.401.96
B26362.890.110.01
C37572.372.636.92
D59091.34−1.341.80

Sum of squared residuals J(w⋆)≈1.96+0.01+6.92+1.80=10.69J(w^\star) \approx 1.96 + 0.01 + 6.92 + 1.80 = 10.69. Mean squared error ≈10.69/4≈2.67\approx 10.69/4 \approx 2.67.

Sanity check via orthogonality. The correctness argument above claims X⊤r=0X^\top r = 0 at the optimum, i.e., residuals sum to zero and are uncorrelated with xx. Sum of residuals: −1.40+0.11+2.63−1.34=0.00-1.40+0.11+2.63-1.34 = 0.00 (up to rounding) — confirmed. This is not a coincidence; it is the geometric fact that the residual vector is orthogonal to the column space of XX, and the all-ones column forces ∑ri=0\sum r_i = 0 exactly at the true optimum.

Common pitfalls & traps

PitfallWhy it happensConsequence
Forgetting the bias termOmitting the constant column in XX forces the line through the originSystematically biased predictions when data is not centered at zero
Using SSE instead of MSE when comparing models across dataset sizesSSE grows with nn; MSE does notMisleading comparisons between train/test sets of different sizes
Ignoring collinear or duplicated featuresX⊤XX^\top X becomes singular or near-singularNormal equations have no unique solution; numerically unstable weights
Treating a large R2R^2 as proof the linear model is "correct"Squared-error fit can look good even when residuals show clear nonlinear structureUndetected model misspecification; poor extrapolation
Blindly trusting one huge outlier's influenceSquared loss penalizes large residuals quadraticallyOne bad data point can rotate the fitted line substantially
Confusing "linear in xx" with "linear in ww"The model is linear in the parameters, not necessarily in the raw featuresMissing the fact that polynomial or log features still fit within linear regression

Pioneers & history

The least-squares method predates modern machine learning by two centuries and was developed to solve an astronomical problem: reconciling noisy, overdetermined observations of planetary and cometary orbits.

Origins · 1 minAdrien-Marie Legendre and how this was discovered
AL
Adrien-Marie Legendre
1752–1833 · Paris, developing methods to fit orbits from astronomical observations

Legendre published the method of least squares in 1805 in an appendix on determining the orbits of comets, explicitly proposing the minimization of the sum of squared errors as the criterion for choosing the best-fitting curve through noisy data — the first public statement of the method that bears its name today.

CF
Carl Friedrich Gauss
1777–1855 · Göttingen, working on geodesy, astronomy, and the theory of errors

Gauss claimed to have used least squares as early as 1795 and, crucially, supplied its probabilistic justification: he showed that least squares is the maximum-likelihood estimator when errors follow what is now called the Gaussian (normal) distribution, connecting the geometric fitting procedure to a rigorous statistical foundation.

History
1805
Legendre publishes the method of least squares as a practical fitting technique for astronomical data.
1809
Gauss publishes his probabilistic derivation, linking least squares to the normal distribution of errors.
1821
Gauss develops the Gauss–Markov theorem, showing least-squares estimators are best linear unbiased estimators under mild assumptions.
1886
Francis Galton studies "regression toward the mean" in heredity, coining the term "regression."
1970
Hoerl and Kennard introduce ridge regression, adding an L2 penalty to stabilize least squares under collinearity.

Where this matters

Linear regression fit by least squares is the workhorse of quantitative fields far beyond machine learning. In economics and finance, it underlies hedonic pricing models, CAPM asset-pricing regressions, and demand forecasting. In the sciences, it is the default tool for quantifying how one measured quantity depends on another, and its assumptions (linearity, homoscedastic Gaussian noise) are taught as the baseline model against which more complex ones are judged. In engineering, it is used for calibration curves, sensor fusion, and system identification, where fast, interpretable, closed-form fits are valuable in real time. Inside machine learning systems, least-squares linear regression appears as a baseline model against which every fancier method is benchmarked, as the final layer of many regression networks (a linear readout on top of learned features), and as the core building block generalized by Ridge Regression and L2 Regularization (adding a penalty for numerical stability and to control overfitting) and by Logistic Regression and the Sigmoid (replacing the identity output with a sigmoid for classification). The two solution methods it sets up — direct linear-algebra solves via the Normal Equations and iterative first-order optimization via Gradient Descent — recur throughout the rest of supervised learning, from support vector machines to the training of deep neural networks, making this simple model an essential template rather than a historical curiosity.

Ask the tutor: If two features in my dataset are almost perfectly correlated, what happens to the least-squares weights, and how does ridge regression fix it?

Is linear regression only useful when the true relationship is a straight line?

No. The model is linear in its parameters ww, not necessarily in the raw input variables. By constructing features such as x2x^2, log⁡x\log x, or interaction terms like x1x2x_1 x_2 and feeding them into the same linear model, you can fit curves, polynomials, and more complex surfaces while keeping the convex least-squares machinery intact. This is why linear regression underlies polynomial regression and many basis-function methods — the fitting procedure stays exactly the same; only the feature construction step changes. The key restriction is that predictions must remain a linear (affine) combination of whatever features are given.

What's the difference between minimizing SSE and minimizing MSE?

Sum of squared errors (SSE) is ∑iri2\sum_i r_i^2; mean squared error (MSE) divides that by nn. Since dividing by the constant nn does not change where the minimum occurs, both objectives yield the identical optimal weight vector w⋆w^\star. The distinction matters for interpretation and comparison: MSE is comparable across datasets of different sizes and has natural units (squared target units), while SSE grows mechanically with more data and is harder to compare across experiments. Most practical reporting and many optimization libraries default to MSE for this reason.

Why does linear regression require X^T X to be invertible, and what happens if it isn't?

The closed-form solution w⋆=(X⊤X)−1X⊤yw^\star = (X^\top X)^{-1} X^\top y requires X⊤XX^\top X to be invertible, which holds precisely when the columns of XX (the features) are linearly independent and there are at least as many independent data points as features. If features are collinear (e.g., one is an exact multiple of another) or there are more features than examples, X⊤XX^\top X is singular, and infinitely many weight vectors achieve the same minimal loss. In practice this is handled either by removing redundant features, using a pseudo-inverse for a minimum-norm solution, or adding an L2 penalty as in Ridge Regression and L2 Regularization, which makes the matrix invertible by construction.

How is linear regression related to maximum likelihood estimation?

If you assume the target is generated as y=w⊤x+εy = w^\top x + \varepsilon with ε∼N(0,σ2)\varepsilon \sim \mathcal{N}(0, \sigma^2) independently for each example, the log-likelihood of the observed data as a function of ww reduces to a negative constant times the sum of squared residuals, plus terms that don't depend on ww. Maximizing this log-likelihood over ww is therefore mathematically identical to minimizing the sum of squared residuals. This equivalence is why least squares is described as the maximum-likelihood estimator under Gaussian noise, and it is the deeper statistical reason squared error was chosen rather than, say, absolute error.

Does a low training loss mean the linear model has found the "true" relationship?

Not necessarily. A low sum-of-squared-errors on the training data only shows the model fits the observed points well; it says nothing directly about how well it will predict new, unseen data, nor whether a linear function is even the right shape for the underlying relationship. Overfitting can occur with enough features (especially engineered polynomial ones), and misspecification can occur if the true relationship is genuinely nonlinear even though the fitted line looks reasonable on a scatter plot. Practitioners check residual plots, use held-out test sets, and compare against regularized or nonlinear alternatives before trusting a fit.

How does linear regression connect to gradient descent and the normal equations?

Least squares defines what to optimize — the convex quadratic objective J(w)=∥y−Xw∥2J(w) = \|y - Xw\|^2 — but not how to optimize it. The normal equations exploit the fact that this specific objective has a closed-form stationary point reachable via linear algebra, solved in one shot for moderate feature counts. Gradient descent instead follows the negative gradient of J(w)J(w) downhill iteratively, useful when the feature count is huge or the matrix inversion is impractical. Both methods provably converge to the same global minimum precisely because J(w)J(w) is convex, which is the central correctness guarantee established in this article.

What's the difference between linear regression and logistic regression?

Linear regression predicts a continuous, unbounded target using y^=w⊤x+b\hat y = w^\top x + b and squared-error loss, which matches a Gaussian noise assumption. Logistic regression instead predicts a probability in [0,1][0,1] for a binary outcome, applying a sigmoid function to w⊤x+bw^\top x + b and fitting parameters by maximizing likelihood under a Bernoulli (rather than Gaussian) assumption, which yields the cross-entropy loss instead of squared error. Both share the same underlying "linear score, then loss derived from a noise/observation model" structure, which is why Logistic Regression and the Sigmoid is best understood as a direct extension of the ideas developed here.

Where this leads