Skip to content

Add random_state parameter to AffinityPropagation#14337

Closed
rcwoolston wants to merge 7 commits intoscikit-learn:masterfrom
rcwoolston:affinity_prop_seed
Closed

Add random_state parameter to AffinityPropagation#14337
rcwoolston wants to merge 7 commits intoscikit-learn:masterfrom
rcwoolston:affinity_prop_seed

Conversation

@rcwoolston
Copy link
Copy Markdown
Contributor

Added random_state parameter to allow user to select the seed.

Relates to issue #14302

@amueller
Copy link
Copy Markdown
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
Copy Markdown
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

else (np.array([0]), np.array([0] * n_samples)))

random_state = np.random.RandomState(0)
if random_state is None:
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.

We have a util for that: utils.check_random_state

Copy link
Copy Markdown
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
Copy Markdown
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

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
Copy Markdown
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
Copy Markdown
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.

6 participants