Skip to content

TST tight and clean tests for Ridge #22910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a13bfa3
MNT replace pinvh by solve
lorentzenchr Mar 19, 2022
d256b5a
DOC more info for svd solver
lorentzenchr Mar 20, 2022
0fc7f3b
TST rewrite test_ridge
lorentzenchr Mar 20, 2022
c61d607
MNT remove test_ridge_singular
lorentzenchr Mar 20, 2022
de36810
MNT restructure into several tests
lorentzenchr Mar 20, 2022
36eee8f
MNT remove test_toy_ridge_object
lorentzenchr Mar 20, 2022
070ba8b
MNT remove test_ridge_sparse_svd
lorentzenchr Mar 20, 2022
69ae791
TST exclude cholesky from singular problem
lorentzenchr Mar 20, 2022
8241d25
CLN two fixes
lorentzenchr Mar 20, 2022
a4fb6ea
MNT parametrize test_ridge_sample_weights
lorentzenchr Mar 20, 2022
f1041f3
MNT restructure test_ridge_sample_weights
lorentzenchr Mar 21, 2022
11ccbc7
CLN tighten tolerance for sag solver
lorentzenchr Mar 21, 2022
77268b9
CLN try to fix saga tolerance
lorentzenchr Mar 21, 2022
72d0962
CLN make test_ridge_sample_weights nicer
lorentzenchr Mar 22, 2022
2b24cf8
MNT remove test_ridge_regression_sample_weights
lorentzenchr Mar 22, 2022
0ad5352
MNT rename to test_ridge_regression_sample_weights
lorentzenchr Mar 22, 2022
a0fe6c0
CLN make test_ridge_regression_unpenalized pass for all random seeds
lorentzenchr Mar 22, 2022
e3f8cee
CLN make tests pass for all random seeds
lorentzenchr Mar 22, 2022
6ecf566
DOC fix typos
lorentzenchr Mar 23, 2022
085bd47
TST skip cholesky for singular problems
lorentzenchr Mar 23, 2022
b383636
MNT move up test_ridge_regression_sample_weights
lorentzenchr Mar 23, 2022
ee0904a
CLN set skip reason as comment
lorentzenchr Mar 23, 2022
c1bc41c
Merge branch 'main' into clean_ridge_tests
lorentzenchr Mar 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sklearn/linear_model/_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ def ridge_regression(
- 'auto' chooses the solver automatically based on the type of data.

- 'svd' uses a Singular Value Decomposition of X to compute the Ridge
coefficients. More stable for singular matrices than 'cholesky'.
coefficients. It is the most stable solver, in particular more stable
for singular matrices than 'cholesky' at the cost of being slower.

- 'cholesky' uses the standard scipy.linalg.solve function to
obtain a closed-form solution via a Cholesky decomposition of
Expand Down Expand Up @@ -971,7 +972,8 @@ class Ridge(MultiOutputMixin, RegressorMixin, _BaseRidge):
- 'auto' chooses the solver automatically based on the type of data.

- 'svd' uses a Singular Value Decomposition of X to compute the Ridge
coefficients. More stable for singular matrices than 'cholesky'.
coefficients. It is the most stable solver, in particular more stable
for singular matrices than 'cholesky' at the cost of being slower.

- 'cholesky' uses the standard scipy.linalg.solve function to
obtain a closed-form solution.
Expand Down Expand Up @@ -1275,7 +1277,8 @@ class RidgeClassifier(_RidgeClassifierMixin, _BaseRidge):
- 'auto' chooses the solver automatically based on the type of data.

- 'svd' uses a Singular Value Decomposition of X to compute the Ridge
coefficients. More stable for singular matrices than 'cholesky'.
coefficients. It is the most stable solver, in particular more stable
for singular matrices than 'cholesky' at the cost of being slower.

- 'cholesky' uses the standard scipy.linalg.solve function to
obtain a closed-form solution.
Expand Down
5 changes: 2 additions & 3 deletions sklearn/linear_model/tests/test_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from math import log

import numpy as np
from scipy.linalg import pinvh
import pytest


Expand Down Expand Up @@ -73,9 +72,9 @@ def test_bayesian_ridge_score_values():
score = lambda_1 * log(lambda_) - lambda_2 * lambda_
score += alpha_1 * log(alpha_) - alpha_2 * alpha_
M = 1.0 / alpha_ * np.eye(n_samples) + 1.0 / lambda_ * np.dot(X, X.T)
M_inv = pinvh(M)
M_inv_dot_y = np.linalg.solve(M, y)
score += -0.5 * (
fast_logdet(M) + np.dot(y.T, np.dot(M_inv, y)) + n_samples * log(2 * np.pi)
fast_logdet(M) + np.dot(y.T, M_inv_dot_y) + n_samples * log(2 * np.pi)
)

# compute score with BayesianRidge
Expand Down
Loading