Skip to content
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

[MRG] Add random_state parameter to AffinityPropagation #16801

Merged
merged 47 commits into from
May 5, 2020

Conversation

cmarmo
Copy link
Contributor

@cmarmo cmarmo commented Mar 29, 2020

Reference Issues/PRs

Continues and closes #14337.

What does this implement/fix? Explain your changes.

Addresses comments in #14337:

  • add parameter to AffinityPropagation class,
  • add test,
  • add what's new entry.

Any other comments?

This is the last open PR from the 2019 Scipy Sprint.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Thanks @cmarmo

sklearn/cluster/_affinity_propagation.py Outdated Show resolved Hide resolved
sklearn/cluster/_affinity_propagation.py Outdated Show resolved Hide resolved
sklearn/cluster/_affinity_propagation.py Show resolved Hide resolved
@adrinjalali
Copy link
Member

Whenever we change the behavior of a mode/method/etc, we tend to deprecate the old behavior away, instead of changing it immediately. The exceptions are bug fixes, which we just fix them and as a result there's a change in the model's behavior.

In this case, the model's behavior has been that it's deterministic with a random seed of 0. We're changing the behavior now to be non-deterministic when the default random_state is None. In a way, we can think of it as changing the default value of random_state from 0 to None.

I'd also be happy if we think this is simply a bug fix and therefore doesn't require deprecation. We can wait for another opinion on this one :)

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 @cmarmo , looks good.

I agree the backward compat is an issue. I'm not sure we can make it a bugfix, that'd be pushing it IMHO. One option is to default to e.g. random_state='warn' now which would be equivalent to 0 and which would raise a warning telling users to set it manually, and switch to None is 2 versions. But that's a bit annoying for them because we're warning on perfectly fine code.

sklearn/cluster/_affinity_propagation.py Outdated Show resolved Hide resolved
sklearn/cluster/_affinity_propagation.py Outdated Show resolved Hide resolved
sklearn/cluster/_affinity_propagation.py Outdated Show resolved Hide resolved
doc/whats_new/v0.23.rst Outdated Show resolved Hide resolved
sklearn/cluster/tests/test_affinity_propagation.py Outdated Show resolved Hide resolved
cmarmo and others added 7 commits March 30, 2020 14:04
Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
@cmarmo
Copy link
Contributor Author

cmarmo commented Apr 1, 2020

🎉

@cmarmo
Copy link
Contributor Author

cmarmo commented Apr 1, 2020

The failing test is in master.

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.

LGTM

@cmarmo
Copy link
Contributor Author

cmarmo commented May 5, 2020

@adrinjalali I'm wondering if this one could still be considered for 0.23... thanks!

@NicolasHug
Copy link
Member

The current solution now throws a warning for perfectly fine code and that's not ideal. I don't know what others think?
Maybe you'll want to discuss this during the next meeting @cmarmo .

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM. I'm not worried about the warning by default, since it's the same in many other cases when we deprecate or change the behavior of a parameter, so there's nothing new there.

Comment on lines 148 to 149
"call. To silence this warning and obtain the same "
"results as before 0.23, set it to 0."),
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 suggest this to recommend users to set it explicitly to None rather than 0. Maybe something like:

"Set random_state to None to silence this warning, or to 0 to keep the deprecated behavior."

Copy link
Member

Choose a reason for hiding this comment

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

deprecated -> previous

there's no deprecated behaviour

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I don't mind. I consider the default value 0 as the random seed deprecated, but don't really mind.

@NicolasHug
Copy link
Member

so there's nothing new there.

I personally don't recall doing something like this in the past. We usually change the default behaviour of an existing parameter, or we rename it so as to get a more sensible name.

But that's different here: we're adding a new parameter and we cannot set its default in a backward compatible way. I would be more comfortable with additional opinions.

@adrinjalali
Copy link
Member

@rth WDYT?

@rth
Copy link
Member

rth commented May 5, 2020

The current solution now throws a warning for perfectly fine code and that's not ideal. I don't know what others think?

You mean that it raises a warning with default parameters? As soon as the user provides any random state be it 0 or None, there should be no warning, right?

+1 For the #16801 (comment) otherwise I don't really see what we could do better and the current approach sounds reasonable to me.

@adrinjalali
Copy link
Member

Shall we merge then @NicolasHug ?

@adrinjalali
Copy link
Member

Merging with 3 approvals, happy to chat about it in our call :)

@adrinjalali adrinjalali merged commit f72d971 into scikit-learn:master May 5, 2020
adrinjalali added a commit to adrinjalali/scikit-learn that referenced this pull request May 5, 2020
…6801)

* Added value checks and random state parameter to method

* Changed default parameter to None instead of 0

* Added numpy RandomState to the check

* Replaced inline validation with check_random_state from utils and pointed at glossery

* Needed a different default parameter to pass the default way this has been working in the past

* Updated to conform with flake8 stds

* Add random_state to AffinityPropagation class.

* Add test.

* Add what's new entry and versionadded directive.

* Add PR number.

* Fix lint error due to this PR.

* Use np.array_equal in test.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Adrin Jalali <adrin.jalali@gmail.com>

* Homogenize parametre descriptions, default random_state to None.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update doc/whats_new/v0.23.rst

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Change test name.

* Modify check in test.

* Fix lint errors.

* Address comment.

* Address comment.

* Add 'deprecation' and its correspondent test.

* Fix lint errors.

* Add random_state parameter to tests, to avoid FutureWarnings.

* Move warning in fit. Modify tests.

* Modify example.

* Tentative fix for failures.

* Document default value to 0. Revert docstring.

* Explicit link to Glossary.

* Fix default value.

* Remove some warnings from tests.

* Validate and test docstring.

* Tentative fix.

* Tentative fix.

* Ignore FutureWarning in fit attribute test.

* Set random_state to avoid FutureWarning in test_fit_docstring_attributes.

* [doc build] Force documentation build.

* Clarify warning message.

Co-authored-by: rwoolston.admin <rwoolston.admin@LXO-DS-DEV.afcucorp.local>
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
adrinjalali added a commit that referenced this pull request May 5, 2020
* Added value checks and random state parameter to method

* Changed default parameter to None instead of 0

* Added numpy RandomState to the check

* Replaced inline validation with check_random_state from utils and pointed at glossery

* Needed a different default parameter to pass the default way this has been working in the past

* Updated to conform with flake8 stds

* Add random_state to AffinityPropagation class.

* Add test.

* Add what's new entry and versionadded directive.

* Add PR number.

* Fix lint error due to this PR.

* Use np.array_equal in test.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Adrin Jalali <adrin.jalali@gmail.com>

* Homogenize parametre descriptions, default random_state to None.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update doc/whats_new/v0.23.rst

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Change test name.

* Modify check in test.

* Fix lint errors.

* Address comment.

* Address comment.

* Add 'deprecation' and its correspondent test.

* Fix lint errors.

* Add random_state parameter to tests, to avoid FutureWarnings.

* Move warning in fit. Modify tests.

* Modify example.

* Tentative fix for failures.

* Document default value to 0. Revert docstring.

* Explicit link to Glossary.

* Fix default value.

* Remove some warnings from tests.

* Validate and test docstring.

* Tentative fix.

* Tentative fix.

* Ignore FutureWarning in fit attribute test.

* Set random_state to avoid FutureWarning in test_fit_docstring_attributes.

* [doc build] Force documentation build.

* Clarify warning message.

Co-authored-by: rwoolston.admin <rwoolston.admin@LXO-DS-DEV.afcucorp.local>
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
@cmarmo cmarmo deleted the affinity_prop_seed branch May 5, 2020 16:19
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
…6801)

* Added value checks and random state parameter to method

* Changed default parameter to None instead of 0

* Added numpy RandomState to the check

* Replaced inline validation with check_random_state from utils and pointed at glossery

* Needed a different default parameter to pass the default way this has been working in the past

* Updated to conform with flake8 stds

* Add random_state to AffinityPropagation class.

* Add test.

* Add what's new entry and versionadded directive.

* Add PR number.

* Fix lint error due to this PR.

* Use np.array_equal in test.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Adrin Jalali <adrin.jalali@gmail.com>

* Homogenize parametre descriptions, default random_state to None.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update doc/whats_new/v0.23.rst

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Change test name.

* Modify check in test.

* Fix lint errors.

* Address comment.

* Address comment.

* Add 'deprecation' and its correspondent test.

* Fix lint errors.

* Add random_state parameter to tests, to avoid FutureWarnings.

* Move warning in fit. Modify tests.

* Modify example.

* Tentative fix for failures.

* Document default value to 0. Revert docstring.

* Explicit link to Glossary.

* Fix default value.

* Remove some warnings from tests.

* Validate and test docstring.

* Tentative fix.

* Tentative fix.

* Ignore FutureWarning in fit attribute test.

* Set random_state to avoid FutureWarning in test_fit_docstring_attributes.

* [doc build] Force documentation build.

* Clarify warning message.

Co-authored-by: rwoolston.admin <rwoolston.admin@LXO-DS-DEV.afcucorp.local>
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
viclafargue pushed a commit to viclafargue/scikit-learn that referenced this pull request Jun 26, 2020
…6801)

* Added value checks and random state parameter to method

* Changed default parameter to None instead of 0

* Added numpy RandomState to the check

* Replaced inline validation with check_random_state from utils and pointed at glossery

* Needed a different default parameter to pass the default way this has been working in the past

* Updated to conform with flake8 stds

* Add random_state to AffinityPropagation class.

* Add test.

* Add what's new entry and versionadded directive.

* Add PR number.

* Fix lint error due to this PR.

* Use np.array_equal in test.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Adrin Jalali <adrin.jalali@gmail.com>

* Homogenize parametre descriptions, default random_state to None.

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update sklearn/cluster/_affinity_propagation.py

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Update doc/whats_new/v0.23.rst

Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>

* Change test name.

* Modify check in test.

* Fix lint errors.

* Address comment.

* Address comment.

* Add 'deprecation' and its correspondent test.

* Fix lint errors.

* Add random_state parameter to tests, to avoid FutureWarnings.

* Move warning in fit. Modify tests.

* Modify example.

* Tentative fix for failures.

* Document default value to 0. Revert docstring.

* Explicit link to Glossary.

* Fix default value.

* Remove some warnings from tests.

* Validate and test docstring.

* Tentative fix.

* Tentative fix.

* Ignore FutureWarning in fit attribute test.

* Set random_state to avoid FutureWarning in test_fit_docstring_attributes.

* [doc build] Force documentation build.

* Clarify warning message.

Co-authored-by: rwoolston.admin <rwoolston.admin@LXO-DS-DEV.afcucorp.local>
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
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