ML0201 Why Linear Regression Can’t Classify

Why can’t you just use linear regression for classification? What goes wrong with the predictions and the decision boundary?

Three dashed panels on a whiteboard card. Panel 1, the setup: one feature, minutes watched, and a label of 1 if the viewer sent a gift; no gift at 5, 10, 15 and 20 minutes and a gift at 30, 35, 40 and 45 minutes; least squares is fit on the 0/1 labels and a gift is predicted when the score is at least 0.5. Panel 2, what the dashboard showed: scores leave the 0 to 1 range, with -0.17 at 5 minutes and 1.17 at 45 minutes; after one gifter at 200 minutes is added and the model is refit, that gifter scores 1.25 and the 30-minute gifter drops to 0.49 and is predicted no gift. Panel 3, the open question: is a 0.5 cut on a straight line a real classifier, why does a correct far-away gifter move the boundary, and should the team keep it, clip it, or change the model

The Problem: A team building gift prediction for a live-streaming app such as Bigo Live fits least squares on 0/1 labels for 8 sessions and cuts the score at 0.5, which separates them cleanly at 25 minutes watched. The scores already run from -0.17 to 1.17, and after one 200-minute gifter is added the 30-minute gifter drops to 0.49 and is predicted to send nothing.

Answer

You can fit least squares to 0/1 labels and cut the score at 0.5, and on clean, balanced data it often separates the classes about as well as logistic regression. The trouble is that it optimizes the wrong objective for the wrong output space. Its predictions lie on an unbounded straight line, so scores like -0.17 or 1.25 appear and cannot be read as probabilities. Squared loss also charges confidently correct points, so a far-away example on the right side still pulls the line toward itself and slides the 0.5 crossing past nearby points. Logistic regression fixes both by passing the score through a sigmoid and training with log loss, whose gradient fades to zero once a point is classified with confidence.

(1) Unbounded Scores: \hat y = w^\top x + b ranges over the whole real line, so scores below 0 and above 1 are routine. They cannot drive a decision that needs a probability, such as a cost-weighted threshold or an expected-revenue estimate.
(2) Squared Loss Punishes Being Too Right: A positive scored 1.5 costs (1.5 - 1)^2 = 0.25, exactly as much as a borderline positive scored 0.5. The fit therefore bends toward confidently correct points instead of ignoring them.
(3) Boundary Pulled By Leverage: The per-point pull 2(\hat y_i - y_i) grows without limit, so one far-away, correctly labeled example tilts the line and slides the 0.5 crossing past nearby points of its own class.
(4) Wrong Noise Model: Least squares is the maximum-likelihood fit for Gaussian noise with constant variance, but a 0/1 label is Bernoulli with variance p(1 - p). Standard errors, R-squared, and any probability reading of the scores inherit that mismatch.
(5) The Fix Is The Loss: Logistic regression keeps a linear boundary but models P(y = 1 \mid x) with a sigmoid and trains on log loss, whose gradient p_i - y_i is bounded and vanishes for well-classified points.

Mathematical Formulation:
\hat y = w^\top x + b
\mathcal{L}_{\mathrm{SE}} = \sum_{i=1}^{N} (y_i - \hat y_i)^2
\partial \mathcal{L}_{\mathrm{SE}} / \partial \hat y_i = 2(\hat y_i - y_i)
x^\ast = (0.5 - b) / w
z_i = w^\top x_i + b
p_i = \sigma(z_i) = 1 / (1 + e^{-z_i})
\mathcal{L}_{\mathrm{log}} = -\sum_{i=1}^{N} \Big( y_i \log p_i + (1 - y_i) \log(1 - p_i) \Big)
\partial \mathcal{L}_{\mathrm{log}} / \partial z_i = p_i - y_i

Where:

  • \hat y is the least-squares score for a feature vector x (here a single feature, minutes watched), with weights w and intercept b. In one dimension w is a scalar slope.
  • y_i \in \{0, 1\} is the label of example i \in \{1, \ldots, N\}, and \mathcal{L}_{\mathrm{SE}} is the sum of squared errors that least squares minimizes.
  • \partial \mathcal{L}_{\mathrm{SE}} / \partial \hat y_i is the pull example i exerts on the fit. It grows linearly with the residual on either side of the label, so a score of 6 on a positive pulls as hard as a score of -4.
  • x^\ast is the one-dimensional least-squares decision boundary, the feature value where \hat y crosses 0.5.
  • z_i is the logit, \sigma the sigmoid, and p_i the predicted probability of class 1, always strictly between 0 and 1. The logistic boundary is z = 0, which is still a linear boundary.
  • \mathcal{L}_{\mathrm{log}} is the Bernoulli negative log-likelihood. Its gradient p_i - y_i lies between -1 and 1 and goes to 0 as a correct prediction becomes confident.

Worked Example:
Take eight sessions: no gift at 5, 10, 15, 20 minutes and a gift at 30, 35, 40, 45 minutes. Least squares gives \hat y = -1/3 + x/30, which crosses 0.5 at exactly 25 minutes and classifies all 8 correctly, yet already scores the 5-minute session at -0.17 and the 45-minute gifter at 1.17. Now add one heavy gifter (a “whale”) who watched 200 minutes. The old line scores that point 6.33, a squared error of 5.33^2 = 28.4 against 0.33 for the other eight combined, so the refit must flatten: \hat y \approx 0.358 + 0.00445\,x. The 0.5 crossing moves to about 32.0 minutes, the 30-minute gifter falls to 0.49 and is misclassified, and training accuracy drops from 8/8 to 8/9 although the new point was the easiest positive in the data. A lightly L2-regularized logistic regression on the same nine points keeps its boundary at 25.0 minutes, because the whale’s log loss is below 10^{-17} and contributes no gradient.

Two-panel chart of model output against minutes watched, with shaded bands above 1 and below 0. Panel a, zoomed on 0 to 60 minutes: no-gift sessions at 5, 10, 15 and 20 minutes sit at 0 and gift sessions at 30, 35, 40 and 45 minutes sit at 1; the 8-session least-squares line (gray dashed) crosses 0.5 at 25 minutes, the refit least-squares line after adding a 200-minute gifter (orange) is flatter and crosses 0.5 at 32 minutes, scoring the ringed 30-minute gifter 0.49, while the logistic curve (blue) still crosses 0.5 at 25 minutes. Panel b, full range 0 to 215 minutes: the 200-minute gifter at label 1 is scored 1.25 by the refit line, and the old line would have scored it 6.33

Figure 1: (a) Before the far gifter, least squares (gray) and logistic regression both cut at 25 minutes. One correctly labeled 200-minute gifter flattens the least-squares line (orange), its 0.5 crossing slides to about 32 minutes, and the 30-minute gifter falls to 0.49. The logistic boundary (blue) stays at 25 minutes. (b) The full range shows the cause: the old line would have scored that gifter 6.33, and even the refit scores it 1.25, outside the shaded valid range.

Both models draw a linear boundary, so the difference is not the shape of the boundary but where the loss places it and what the output means. The table lines the two up on the properties that matter for a classifier.

PropertyLeast squares on 0/1 labelsLogistic regression
Output rangeAny real number, e.g. -0.17 or 1.25Strictly between 0 and 1 through the sigmoid
LossSquared error (y – y_hat)^2Log loss (Bernoulli negative log-likelihood)
Confidently correct pointStill penalized; pull 2(y_hat – y) grows without boundPull p – y shrinks toward 0
Far, correctly labeled exampleTilts the line; cut slides from 25 to 32 minutesBoundary stays at 25 minutes
Implied noise modelGaussian with constant varianceBernoulli with variance p(1 – p)
Decision boundaryLinear, where the score equals 0.5Linear, where the logit equals 0
FittingClosed form via the normal equationsIterative (Newton or gradient descent) on a convex loss

Login to view more content
Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *