Part 1: Core setup - Least squares residual is orthogonal to column space
State the objects, shapes, and target question for Least squares residual is orthogonal to column space. Name the data matrices or vectors, specify their dimensions, and clarify the transformation or comparison this example develops.
Part 2: Geometry and algebraic insight - Least squares residual is orthogonal to column space
Describe the geometric picture (subspaces, projections, bases, or decompositions) and the algebraic identities that make Least squares residual is orthogonal to column space work. Highlight how these structures constrain solutions and connect to earlier linear algebra tools.
Part 3: Numerics and ML practice - Least squares residual is orthogonal to column space
Give the computational recipe for Least squares residual is orthogonal to column space, note stability or conditioning checks, and tie to an ML use case. Mention parameter choices, common pitfalls, and quick sanity checks such as shape validation or reconstruction error.
- Shape discipline: check dimensions before manipulating formulas.
- Numerical note: prefer stable primitives (
lstsq, QR/SVD, Cholesky for SPD) over explicit inverses.
- Interpretation: relate algebraic steps to geometry (subspaces, projections) and to ML behavior (generalization, stability).
Numerical notes: np.linalg.lstsq is typically stable for moderate conditioning because it leverages QR/SVD rather than inverting $X^\top X$. In float64, a well-posed problem should yield $\|X^\top r\|_2$ close to machine precision; choose a tolerance appropriate to data scale (e.g., compare $\|X^\top r\|_2$ to $\|X\|\,\|r\|$). If $\|X^\top r\|$ is unexpectedly large, inspect singular values (SVD), rescale columns, or regularize. Finally, assert shapes: $(n,d)$ for $X$, $(d,)$ for $w$, $(n,)$ for $y$ and $r$, and $(d,)$ for $X^\top r$.
Comments