Orthogonality, Projection, and Least Squares

Objectives

You will understand orthogonal projection and least squares as finding the nearest point in a subspace, derive the residual-orthogonality condition, distinguish uniqueness of a fitted value from uniqueness of parameters, and know that normal equations are useful for explanation but should not be mechanically implemented through an explicit inverse.

Orthogonality and projection

If , the two vectors are orthogonal. Project onto the direction of a nonzero vector as:

For example, if and , the projection is , and the residual is orthogonal to .

If are pairwise orthogonal unit basis vectors and are collected as , then projection onto their column space is:

An orthogonal basis makes coordinates clear and prevents repeated directions from interfering with one another. Gram–Schmidt constructs an orthogonal basis from independent columns; numerical libraries normally use a more stable QR implementation instead of copying the most naive hand-calculation procedure.

Why least squares is projection

When has no exact solution, find that minimizes squared residual length:

is the point in the column space of nearest to , and the residual is orthogonal to that column space:

This gives the normal equations:

That explains linear regression: predictions lie in the space spanned by feature columns, while the remaining error is orthogonal to every feature column.

If has full column rank, the parameter solution is unique. If columns are dependent, the closest fitted vector may still be unique even though multiple parameter vectors produce it. SVD-based least-squares solvers usually choose one minimum-norm solution; consult the particular API contract.

When has full column rank, the theoretical projection matrix is:

This identity is for understanding, not a default implementation recommendation. Explicitly forming an inverse adds computational and numerical risk, and the inverse does not exist when rank is deficient. The next lesson uses condition numbers to explain why QR- and SVD-based paths are safer.

One-variable linear regression

For the model , minimize:

Adding a column of ones to the design matrix incorporates the bias into the parameter vector. The project program uses equivalent closed-form formulas for and checks that the residual sum and the dot product of residuals with centered are close to 0.

After centering , slope and intercept are:

A zero denominator means all values are identical, so the slope cannot be identified from the data. A very small denominator signals an almost-constant feature and a sensitivity risk.

Numerical and statistical boundaries

  • Normal equations are convenient for explanation, but explicitly calculating can amplify numerical problems; production libraries normally use QR, SVD, or a dedicated least-squares solver.
  • Least squares produces an algebraically optimal fit; it does not automatically satisfy statistical assumptions such as causal interpretation, independent and identically distributed data, or homoscedasticity.
  • Outliers are amplified by squared loss. Whether to use a robust loss depends on the data-generating mechanism, not on making a score look better.
  • Minimizing training residuals does not imply best generalization. Data splits, noise, overfitting, and uncertainty must be assessed with Probability and Statistics and Machine Learning.

Connection to embeddings and retrieval

  • Projection decomposes a high-dimensional vector into a component in a subspace plus an orthogonal residual.
  • Dimensionality reduction preserves major structure in a lower-dimensional subspace.
  • Mapping a query into a domain subspace may strengthen relevant directions but can also discard crucial information.
  • The dot product and orthogonality used in cosine similarity arise from the same geometry.

Common pitfalls, exercises, and self-check

  1. Calculate by hand the projection of onto . The coefficient is and the projection is .
  2. Verify that the residual has dot product 0 with .
  3. Use the three points (0,1), (1,3), and (2,5) to calculate slope and intercept by hand.
  4. Explain why “the fitted vector may be unique” and “the parameters are not unique” can both be true for dependent columns.
  5. Give an outlier scenario that is unsuitable for squared loss, and describe the data mechanism that needs checking.

Pitfalls: the nearest point depends on the selected norm; an nearest point is not optimal under every loss; feature scaling affects regularization and numerical conditioning; and a non-invertible matrix should not be forcibly inverted.

  • I can explain normal equations through projection.
  • I know that engineering code should not default to explicit inversion.
  • I can distinguish algebraic fitting from a statistical causal conclusion.
  • I can write the one-variable closed form and recognize the rank issue caused by a zero denominator.
  • I know that parameter uniqueness depends on column rank.

References

Verified on 2026-07-14.

Previous: Linear transformations and neural networks · Next: Numerical stability and condition numbers.