Ridge regression minimizes (no intercept). Its solution is , but forming and inverting is slow and numerically fragile. Implement two stable solvers and the effective degrees of freedom.
ridge_svd(X, y, lam): compute from the thin SVD (np.linalg.svd(X, full_matrices=False)). Must work when .ridge_augmented_qr(X, y, lam): append "virtual" rows to and zeros to , take the reduced QR decomposition of the stacked matrix, and solve the triangular system by back-substitution (write the loop yourself). Assume .ridge_dof(X, lam): the effective degrees of freedom over the singular values of .ridge_shrinkage(X, lam): the vector of shrinkage factors , in the order np.linalg.svd returns the singular values (largest first).Return NumPy arrays (floats for ridge_dof).