Minimum-Norm Exact Solution for a Wide (n < p) Linear Regression System in NumPy

Quick Overview

Implement the minimum-norm exact solution of a wide linear system, with more columns than rows, in NumPy and report the largest absolute residual. It tests the pseudoinverse, why the row-space solution has the smallest norm, and why the normal equations break down when p exceeds n.

Minimum-Norm Exact Solution for a Wide (n < p) Linear Regression System in NumPy

Role: Data Scientist

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Implement `def underdetermined_min_norm(X: np.ndarray, y: np.ndarray) -> tuple[np.ndarray, float]`. `X` is float64 of shape `(n, p)` with `n < p` and full row rank (it already includes any intercept column), and `y` is float64 of shape `(n,)`. Return the minimum-norm exact solution: the `beta` with the smallest `||beta||_2` satisfying `X @ beta == y`. Requirements: - Return the 2-tuple `(beta, max_abs_residual)`. - `beta` is an ndarray of shape `(p,)`, matching `np.linalg.pinv(X) @ y` or `np.linalg.lstsq(X, y, rcond=None)[0]`. - `max_abs_residual` is a native Python `float` equal to `np.max(np.abs(X @ beta - y))` (about 0). - Do not add an intercept column. Use `X` exactly as given. Example: ```python X = np.array([[1., 0., 1.], [0., 1., 1.]]) y = np.array([1., 2.]) beta, max_abs_residual = underdetermined_min_norm(X, y) # beta is close to [0., 1., 1.] (norm sqrt(2)) # [1., 2., 0.] also satisfies X @ beta == y, but its norm is sqrt(5) # max_abs_residual is about 0.0 ``` ```hint Many exact solutions Any two exact solutions differ by a vector in the null space of `X`. Ask which part of `beta` you can remove without changing `X @ beta`. ``` ```hint A matrix to avoid With `n < p`, check whether `X.T @ X` is invertible before building anything on the normal equations. ``` ### Constraints & Assumptions - `X` is float64 with shape `(n, p)`, `n < p`, and full row rank. - `X` already contains any intercept column. - `y` is float64 with shape `(n,)`. ### What a Strong Answer Covers - A `beta` that matches the pseudoinverse solution, plus the residual returned as a native float. - Why the system has infinitely many exact solutions and why exactly one of them has the smallest norm. - Why the normal equations fail here and which numerically stable routes work instead. - Using `X` as given, and what residual size to expect. ### Follow-up Questions - Why does the pseudoinverse give the minimum-norm solution specifically? - How would you obtain a sparse solution instead of the minimum-L2 one? - What do `pinv` and `lstsq` return if `X` is not full row rank? - How does the minimum-norm solution relate to ridge regression as the penalty goes to zero?

Overview: Implement the minimum-norm exact solution of a wide linear system, with more columns than rows, in NumPy and report the largest absolute residual. It tests the pseudoinverse, why the row-space solution has the smallest norm, and why the normal equations break down when p exceeds n.

Nov 25, 2026
mediumData ScientistOtherMachine Learning
0
0

Implement def underdetermined_min_norm(X: np.ndarray, y: np.ndarray) -> tuple[np.ndarray, float]. X is float64 of shape (n, p) with n < p and full row rank (it already includes any intercept column), and y is float64 of shape (n,). Return the minimum-norm exact solution: the beta with the smallest ||beta||_2 satisfying X @ beta == y.

Requirements:

  • Return the 2-tuple (beta, max_abs_residual) .
  • beta is an ndarray of shape (p,) , matching np.linalg.pinv(X) @ y or np.linalg.lstsq(X, y, rcond=None)[0] .
  • max_abs_residual is a native Python float equal to np.max(np.abs(X @ beta - y)) (about 0).
  • Do not add an intercept column. Use X exactly as given.

Example:

X = np.array([[1., 0., 1.],
              [0., 1., 1.]])
y = np.array([1., 2.])
beta, max_abs_residual = underdetermined_min_norm(X, y)
# beta is close to [0., 1., 1.]  (norm sqrt(2))
# [1., 2., 0.] also satisfies X @ beta == y, but its norm is sqrt(5)
# max_abs_residual is about 0.0

Constraints & Assumptions

  • X is float64 with shape (n, p) , n < p , and full row rank.
  • X already contains any intercept column.
  • y is float64 with shape (n,) .

What a Strong Answer Covers Guidance

  • A beta that matches the pseudoinverse solution, plus the residual returned as a native float.
  • Why the system has infinitely many exact solutions and why exactly one of them has the smallest norm.
  • Why the normal equations fail here and which numerically stable routes work instead.
  • Using X as given, and what residual size to expect.

Follow-up Questions Guidance

  • Why does the pseudoinverse give the minimum-norm solution specifically?
  • How would you obtain a sparse solution instead of the minimum-L2 one?
  • What do pinv and lstsq return if X is not full row rank?
  • How does the minimum-norm solution relate to ridge regression as the penalty goes to zero?