Repository navigation
feat(linear): add ridge regression - #11
Open
BenjaminLucier wants to merge 1 commit into
Open
BenjaminLucier wants to merge 1 commit into
BenjaminLucier wants to merge 1 commit into
Conversation
Least squares on nearly collinear columns picks large coefficients that cancel out, and a little noise in the targets swings them wildly. Ridge regression adds a penalty alpha * ||coef||² that keeps them small and stable, and is the first penalty on LinearRegressor<P>. Add the Ridge penalty and RidgeRegression = LinearRegressor<Ridge>: new() with alpha 1 (scikit-learn's default), with_alpha, alpha(). It is solved by the same SVD as LinearRegression: both fits now share one private least_squares(data, intercept, alpha), and each kept singular value s contributes 1 / (s + alpha / s) in place of 1 / s, so alpha = 0 is least squares to the bit. The intercept is never penalised. alpha must be finite and non-negative, and finite in the data's float type (InvalidParameter). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Least squares on nearly collinear columns picks large coefficients that
cancel out, and a little noise in the targets swings them wildly. Ridge
regression adds a penalty alpha * ||coef||² that keeps them small and
stable, and is the first penalty on LinearRegressor
.
Add the Ridge penalty and RidgeRegression = LinearRegressor:
new() with alpha 1 (scikit-learn's default), with_alpha, alpha(). It is
solved by the same SVD as LinearRegression: both fits now share one
private least_squares(data, intercept, alpha), and each kept singular
value s contributes 1 / (s + alpha / s) in place of 1 / s, so alpha = 0
is least squares to the bit. The intercept is never penalised. alpha
must be finite and non-negative, and finite in the data's float type
(InvalidParameter).
Tests match scikit-learn's Ridge(solver="svd") to 1e-12 on tall,
strongly penalised, weighted, no-intercept, duplicated-column and wide
data, and check alpha = 0, monotone shrinkage, the unpenalised intercept
and invalid alphas. The linear example and the book's linear page gain a
ridge section; README and AGENTS.md follow.
🤖 Generated with Claude Code