Skip to content
Glacius
Linear algebraConcept reference

Least-squares geometry

A least-squares output is the attainable output that minimizes the sum of squared residual components relative to a target.

On this page 7 sections
  1. Overview
  2. Choose an attainable output
  3. Why the closest point wins
  4. Coefficients and predictions differ
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections
Equal scale of 30 pixels per data unit in both directions, with origin at pixel (45,170). Attainable outputs form the whole line y=x. The target b=(2,4) is off that line; its nearest output p=(3,3) lies on it. The residual arrow b−p=(-1,1) runs from p to b, perpendicular to direction (1,1). A right-angle marker shows this perpendicularity. The x and y axes are context only.Equal scale of 30 pixels per data unit in both directions, with origin at pixel (45,170). Attainable outputs form the whole line y=x. The target b=(2,4) is off that line; its nearest output p=(3,3) lies on it. The residual arrow b−p=(-1,1) runs from p to b, perpendicular to direction (1,1). A right-angle marker shows this perpendicularity. The x and y axes are context only.
Figure 1Equal scale of 30 pixels per data unit in both directions, with origin at pixel (45,170). Attainable outputs form the whole line y=x. The target b=(2,4) is off that line; its nearest output p=(3,3) lies on it. The residual arrow b−p=(-1,1) runs from p to b, perpendicular to direction (1,1). A right-angle marker shows this perpendicularity. The x and y axes are context only.
Link to this figure ↗Download SVGDownload PNG

01Choose an attainable output#

A linear model can produce outputs AxAx by changing its coefficients xx. Measurements bb may fall outside that set. Least squares selects the attainable output with the smallest sum of squared errors.

Suppose the allowed outputs are (t,t)(t,t) and the target is (2,4)(2,4). Matching both coordinates exactly would require t=2t=2 and t=4t=4 simultaneously. The target is inconsistent with the model, so some error remains.

Output (3,3)(3,3) leaves residual b−Ax=(−1,1)b-Ax=(-1,1). Its squared error is (−1)2+12=2(-1)^2+1^2=2. Output (2,2)(2,2) leaves (0,2)(0,2) and squared error 44. Squaring keeps opposite errors from cancelling.

Check your reasoning

Outputs are y=(t,t)y=(t,t) for real tt. Target b=(0,2)b=(0,2). Closest output?

  1. A(0,0)(0,0)
  2. B(1,1)(1,1)
  3. C(−1,1)(-1,1)
Show answer and explanation
(1,1)(1,1)

b−y=(−1,1)b-y=(-1,1) is perpendicular to (1,1)(1,1).

02Why the closest point wins#

Every allowed displacement from (3,3)(3,3) has the form (h,h)(h,h). Its dot product with the residual (−1,1)(-1,1) is zero. The residual is perpendicular to the directions in which the model can move.

Moving to (3+h,3+h)(3+h,3+h) gives squared errors (1+h)2(1+h)^2 and (1−h)2(1-h)^2. Their linear terms cancel when added:

E=2+2h2.E=2+2h^2.

The extra term is nonnegative. No allowed move improves on (3,3)(3,3).

The same reasoning works for a linear output subspace. A perpendicular residual adds no cross term when the squared distance is expanded. Moving away adds the squared length of the allowed displacement.

Check your reasoning

Two channels output (t,−t)(t,-t) for real tt. Target (4,0)(4,0). Minimum sum of squared errors?

Show answer and explanation
8

Closest output (2,−2)(2,-2); error 22+22=82^2+2^2=8.

03Coefficients and predictions differ#

For outputs (2t,t)(2t,t) and target (0,5)(0,5), the closest output is (2,1)(2,1). Its residual (−2,4)(-2,4) is perpendicular to direction (2,1)(2,1) because −4+4=0-4+4=0.

The fitted coefficient is t=1t=1; the fitted output is the pair (2,1)(2,1). Reporting a coefficient when asked for an output confuses two different objects. The nonzero residual does not make this fit incorrect.

Check your reasoning

Outputs: y=(t,0)y=(t,0), real tt. Target b=(3,4)b=(3,4). Claim: exact fit. Closest output?

  1. A(3,0)(3,0)
  2. B(3,4)(3,4)
  3. C(0,0)(0,0)
Show answer and explanation
(3,0)(3,0)

(3,0)(3,0) is attainable; its error is vertical.

If the target already lies in the attainable subspace, its closest output is itself and the minimum error is zero. Otherwise, the closest output still exists in this finite-dimensional linear setting. Whether the coefficients producing it are unique is a separate question.

In ML, this geometry explains the best training fit within a chosen linear model. It does not establish performance on new observations. Computing coefficients efficiently and evaluating generalization have their own lessons.

Key takeaway

Choose an attainable output whose residual is perpendicular to the output subspace.

  • Identify the closest attainable output in an inconsistent linear system.

Sources & further reading

  1. [1]
  2. [2]
  3. [3]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Least-squares geometry.” Math behind ML. /learn/la-least-squares