Chapter 13's lesson When the Normal Equations Break left a fit with no single answer. When columns of the design matrix repeat the same information, such as a length recorded in both feet and inches, is singular, the normal equations have no unique answer, and infinitely many weight vectors tie for the smallest squared error.
The standard way to break the tie is to choose, among all those best-fitting , the one with the smallest length . The pseudoinverse finds it directly from the SVD of Chapter 11:
For an matrix ( examples, features), is . is its counterpart: the same diagonal layout, with each nonzero singular value replaced by . Singular values that are zero stay .
On a computer, a singular value that should be exactly zero usually comes out as a tiny leftover such as . So use this rule: a singular value counts as zero when it is at most times the largest singular value.
Task: write min_norm_weights(X, y) returning as a list, every entry rounded to 4 decimal places.
X is a list of rows, one per example. Its columns may be redundant, and it may have more columns than rows.