8000 Add random_state parameter to AffinityPropagation by rcwoolston · Pull Request #14337 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Add random_state parameter to AffinityPropagation #14337

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

Closed
wants to merge 7 commits into from

Conversation

rcwoolston
Copy link
Contributor

Added random_state parameter to allow user to select the seed.

Relates to issue #14302

@amueller
Copy link
Member

Thanks for the PR. looks good. Can you please add a test checking that this has an effect, and also covering the error message?

Copy link
Member
@NicolasHug NicolasHug 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. Just a few comments

@@ -133,7 +139,10 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200,
if return_n_iter
else (np.array([0]), np.array([0] * n_samples)))

random_state = np.random.RandomState(0)
if random_state is None:
Copy link
Member

Choose a reason for hiding this comment

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

We have a util for that: utils.check_random_state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I am reading the docs right, my if statement should be replaced with utils.check_random_state. @amueller, if that is the case, then do you still want unittests wrapping this function, since they should be caught with unittests from utils.check_random_state? I am good ok with writing those tests, I just want to make sure I following the testing conventions you all use.

Copy link
Member
@NicolasHug NicolasHug Jul 14, 2019

Choose a reason for hiding this comment

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

You used check_random_state correctly @rcwoolston 👍

There is no need to check the error message anymore, however a small test making sure that changing the random_state has an effect on the results would still be helpful.

You have some line-too-long issues as can be seen on the ci/circleci: lint checker. You can also check yourself with make flake8-diff

@@ -72,6 +72,12 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200,
return_n_iter : bool, default False
Whether or not to return the number of iterations.

random_state : int, RandomState instance or None, optional (default=None)
Copy link
Member

Choose a reason for hiding this comment

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

For the details we can just link to the glossary. E.g.:

    random_state : int, np.random.RandomStateInstance or None, \
        optional (default=None)
        Pseudo-random number generator to control XXXX. See :term:`random_state`.

Copy link
Member
@rth rth left a comment

Choose a reason for hiding this comment

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

We should also add this parameter to the AffinityPropagation class.

Also please add an entry to the change log at doc/whats_new/v0.22.rst. Like the other entries there, please reference this pull request with :pr: and credit yourself with :user:.

@rth rth changed the title Added value checks and random state parameter to method Add random_state parameter to AffinityPropagation Oct 29, 2019
@cmarmo cmarmo added the Stalled label Mar 29, 2020
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.

5 participants
0