Skip to content

BUG RidgeCV with gcv_mode="svd" is unstable when alpha is very small #32459

Closed

Description

@antoinebaker

Describe the bug

As observed in this PR #27842 (comment) there is a bug with RidgeCVwith gcv_mode="svd". The problem seems to appear for very small alpha values (1e-14 or less). The other gcv_mode="eigen" works fine.

It's maybe related to this bug #26848 (comment) where alpha is not very small but fitting is done with large sample_weight, again gcv_mode="eigen" works fine but gcv_mode="svd" gives diverging coefficients and very poor score.

Steps/Code to Reproduce

from sklearn.datasets import make_regression
from sklearn.linear_model import RidgeCV
from sklearn.model_selection import train_test_split

alphas = [1e-15, 1e-14]
X, y = make_regression(n_samples=1000, n_features=50, noise=0, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.9, random_state=42)
n_train = X_train.shape[0]
ridge_cv = RidgeCV(alphas=alphas, gcv_mode="svd")
ridge_cv.fit(X_train, y_train)
score = ridge_cv.score(X_test, y_test)
min_coef = ridge_cv.coef_.min()
max_coef = ridge_cv.coef_.max()
print(f"{score=:.2f} {min_coef=:.2f} {max_coef=:.2f}")

Expected Results

We expect an also perfect fit in this case, eg gcv_mode="eigen" gives

# score=1.00 min_coef=-0.00 max_coef=94.78

Actual Results

The score is catastrophic and there is an issue with the fitted coefficients magnitude.

# score=-37754.60 min_coef=-9221.16 max_coef=11981.91

Versions

sklearn: 1.8.dev0

Activity

  1. added
    Needs Triage
    on Oct 9, 2025
  2. added
    Needs Investigation
    and removed
    Needs Triage
    on Oct 9, 2025
  3. antoinebaker commented on Oct 15, 2025

    @antoinebaker
    MemberAuthor

    A possible fix (using the full svd of X) is shown in the linked draft PR.

  4. ogrisel commented on Oct 24, 2025

    @ogrisel
    Member

    Ping @lorentzenchr @agramfort @josephsalmon @mathurinm in case any of you has some spare brain cycle to allocate to interesting numerical stability / linear algebra problems (see ideas explored in #32506 for a start).

  5. changed the title [-]BUG RidgeCV with gcv_mode="svd" is unstable when alpha is very small[/-] [+]BUG `RidgeCV` with `gcv_mode="svd"` is unstable when alpha is very small[/+] on Jan 13, 2026
  6. moved this to Done in Labson Jan 19, 2026
  7. closed this as completedby moving to Done in Labson Jan 19, 2026
  8. moved this from Done to In progress in Labson Jan 19, 2026
  9. moved this from In progress to Done in Labson Jan 19, 2026
  10. moved this from Done to In progress - High Priority in Labson Jan 19, 2026
  11. moved this from In progress - High Priority to In progress in Labson Feb 9, 2026
  12. moved this from In progress to Done in Labson Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds InvestigationNumerical Stability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions