Skip to content

TST adapt tol for ridge tests to pass on all random seeds - #23017

Merged
jeremiedbb merged 3 commits into
scikit-learn:mainfrom
lorentzenchr:fix_ridge_test_precision
Apr 20, 2022
Merged

jeremiedbb merged 3 commits into
scikit-learn:mainfrom
lorentzenchr:fix_ridge_test_precision

Conversation

@lorentzenchr

Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixed #23014.

What does this implement/fix? Explain your changes.

Adapts tolerances to let ridge tests pass on all random seeds

Any other comments?

On my machine, the following passes:

SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all" pytest sklearn/linear_model/tests/test_ridge.py

@lorentzenchr

Copy link
Copy Markdown
Member Author

@jeremiedbb Is there a way to run CI with SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all" just once and just for test_ridge.py?

@lorentzenchr lorentzenchr added the Quick Review For PRs that are quick to review label Apr 1, 2022
@jeremiedbb

Copy link
Copy Markdown
Member

@jeremiedbb Is there a way to run CI with SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all" just once and just for test_ridge.py?

Nope. I'm currently working on it :)


assert_allclose(dense_ridge.intercept_, sparse_ridge.intercept_)
assert_allclose(dense_ridge.coef_, sparse_ridge.coef_)
assert_allclose(dense_ridge.coef_, sparse_ridge.coef_, rtol=5e-7)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change required for test_ridge_fit_intercept_sparse to locally pass for you?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, to pass for all random seeds.

@jeremiedbb

Copy link
Copy Markdown
Member

In test_ridge_regression_vstacked_X I noticed that for some seeds, the coef of a feature can be quite small. It seems to be due to how data is generated. atol should be used to compare zeros (or what we consider being a zero). When most coefs are around 1e0, it's hard to ensure a rtol of 1e-7 on a coef around 1e-5. In this situation, I'd set a atol around 1e-8.

test_ridge_regression_unpenalized_vstacked_X
test_ridge_fit_intercept_sparse

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well. Maybe we could merge both this and #23152 to make the tests even more robust to small platform-specifc variations while not making the test too trivial either.

test_ridge_regression_vstacked_X
test_ridge_fit_intercept_sparse
@jeremiedbb

Copy link
Copy Markdown
Member

Let's merge both

@jeremiedbb
jeremiedbb merged commit 566cc46 into scikit-learn:main Apr 20, 2022
@lorentzenchr
lorentzenchr deleted the fix_ridge_test_precision branch April 20, 2022 17:04
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_ridge_regression_vstacked_X is not stable

5 participants