Skip to content

TST use global_random_seed in sklearn/cluster/tests/test_spectral.py #24802

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

Conversation

irene000
Copy link
Contributor

@irene000 irene000 commented Nov 1, 2022

Reference Issues/PRs

#22827

What does this implement/fix? Explain your changes.

Use global_random_seed in tests of test_spectral.py

Any other comments?

Copy link
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Looks good to me

@cmarmo
Copy link
Contributor

cmarmo commented Nov 11, 2022

Hi @irene000 , thanks for your pull request!
Do you mind running black?

$ black sklearn/cluster/tests/test_spectral.py

This will fix the lint issue and trigger all the other checks. Thanks!

irene000 and others added 8 commits November 13, 2022 04:59
test_spectral_clustering
test_spectral_clustering_sparse
test_precomputed_nearest_neighbors_filtering
test_affinities
test_cluster_qr
test_cluster_qr_permutation_invariance
test_discretize
test_spectral_clustering_with_arpack_amg_solvers
test_n_components
test_spectral_clustering
test_spectral_clustering_sparse
test_precomputed_nearest_neighbors_filtering
test_affinities
test_cluster_qr
test_cluster_qr_permutation_invariance
test_discretize
test_spectral_clustering_with_arpack_amg_solvers
test_n_components
Copy link

github-actions bot commented Apr 10, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 7df86d3. Link to the linter CI: here

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @irene000

@jeremiedbb jeremiedbb enabled auto-merge (squash) April 10, 2025 19:14
@jeremiedbb
Copy link
Member

For the record I slightly modified the dataset in one of the tests because it was failing for a single seed and after a deep dive into the algorithm it turns out that there's inherent randomness in scipy's eigsh which doesn't produce the same results each time with the same args. It happens in rare situations, probably in near degenerate settings, for instance here the eigen values were close to machine precsion.

I suspect that it's just the result of rouding errors that accumulate differently in different calls because of the multi-threaded underlying BLAS/LACPACK calls, in which case it's kind of expected and there's nothing to do about it.

@jeremiedbb jeremiedbb merged commit 65a3e64 into scikit-learn:main Apr 10, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants