Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TST use global_random_seed in sklearn/cluster/tests/test_hierarchical.py #25281

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 3 commits into from
Jan 11, 2023

Conversation

marenwestermann
Copy link
Member

@marenwestermann marenwestermann commented Jan 3, 2023

Reference Issues/PRs

towards #22827

What does this implement/fix? Explain your changes.

I used the global_random_seed fixture in the sklearn/cluster/tests/test_hierarchical.py module where I thought it's appropriate in accordance with the description of the referenced issue.

A few comments about tests where I at first thought the global_random_seed fixture would be useful but didn't apply it:

test_agglomerative_clustering_memory_mapped and test_mst_linkage_core_memory_mapped.
In the documentation of the numpy memmap function on which these tests are based it is said, "Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory." (for reference see here). Therefore I thought the global_random_seed fixture could be useful in these two tests because changing the seed might result in a different small segment being chosen (but I'm not sure if this is correct). When I applied this fixture to these two tests, all tests passed but the former test ran in 1.83 s on my machine (Apple M1 Pro) and the latter ran in 14 s. Because of the rather long run time, I didn't apply the fixture in these tests.

I also tried applying the fixture to the function test_ward_linkage_tree_return_distance and all tests ran successfully. However, the run time on my machine was 1.4 s and I therefore decided against applying this fixture here.

Any other comments?

#PyLadiesParis
I started working on this issue during the PyLadies Paris scikit-learn sprint on 8 Dec 2022.

test_linkage_misc
test_ward_agglomeration
test_ward_tree_children_order
test_small_distance_threshold
test_cluster_distances_with_distance_threshold
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

I would add the fixture to the following tests.

  • test_agglomerative_clustering
  • test_sparse_scikit_vs_scipy
  • test_vector_scikit_single_vs_scipy_single this on is already parameterized with some seed. We can remove them.
  • test_vector_scikit_single_vs_scipy_single
  • test_agglomerative_clustering_with_distance_threshold

Somehow these tests check some equivalence and I think this is worth checking with different inputs to find if there are some corner cases.

@@ -50,9 +50,9 @@
from sklearn.datasets import make_moons, make_circles


def test_linkage_misc():
def test_linkage_misc(global_random_seed):
Copy link
Member

Choose a reason for hiding this comment

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

I would not parametrize this test. There are in general smoke testing more than statistical check. This test would benefit from a refactoring but we can let it as-is for the moment.

@glemaitre
Copy link
Member

I think this is fine to let the test with the memmap out. For the other test since we are running by default a single seed this is fine to have an increase time because it would only be triggered if we enable the test for it.

test_sparse_scikit_vs_scipy
test_vector_scikit_single_vs_scipy_single
test_ward_linkage_tree_return_distance
test_agglomerative_clustering_with_distance_threshold
@marenwestermann
Copy link
Member Author

Thanks for your review @glemaitre. I updated the PR. When I added the global_random_seed fixture to the test test_agglomerative_clustering the run time increased from previously 0.4 sec to 12 sec, so I didn't apply the fixture for this test. If you think that's ok I'll add the fixture to this test as well.

@glemaitre
Copy link
Member

We can add the fixture to this test. The increased time only happens when we request it for this test specifically which is never the case. Here, we only make sure that the test is passing locally whatever the seed. So this is fine.

test_agglomerative_clustering
@marenwestermann
Copy link
Member Author

Ok, thanks. I updated the test.

Copy link
Member

@glemaitre glemaitre 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 @marenwestermann.
Noting as awaiting a second review.

@glemaitre glemaitre added the Waiting for Second Reviewer First reviewer is done, need a second one! label Jan 10, 2023
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! LGTM

@thomasjpfan thomasjpfan merged commit 6ce482c into scikit-learn:main Jan 11, 2023
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Jan 12, 2023
@marenwestermann marenwestermann deleted the test-hierarchical branch January 12, 2023 13:30
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 20, 2023
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 20, 2023
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 23, 2023
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.