[MRG] Add random_state parameter to AffinityPropagation#16801
[MRG] Add random_state parameter to AffinityPropagation#16801adrinjalali merged 47 commits intoscikit-learn:masterfrom
Conversation
… been working in the past
…into affinity_prop_seed
Co-Authored-By: Adrin Jalali <adrin.jalali@gmail.com>
|
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 :) |
NicolasHug
left a comment
There was a problem hiding this comment.
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.
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>
|
🎉 |
|
The failing test is in master. |
|
@adrinjalali I'm wondering if this one could still be considered for 0.23... thanks! |
|
The current solution now throws a warning for perfectly fine code and that's not ideal. I don't know what others think? |
adrinjalali
left a comment
There was a problem hiding this comment.
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.
| "call. To silence this warning and obtain the same " | ||
| "results as before 0.23, set it to 0."), |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
deprecated -> previous
there's no deprecated behaviour
There was a problem hiding this comment.
Sure, I don't mind. I consider the default value 0 as the random seed deprecated, but don't really mind.
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. |
|
@rth WDYT? |
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. |
|
Shall we merge then @NicolasHug ? |
|
Merging with 3 approvals, happy to chat about it in our call :) |
…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>
* 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>
…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>
…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>
Reference Issues/PRs
Continues and closes #14337.
What does this implement/fix? Explain your changes.
Addresses comments in #14337:
Any other comments?
This is the last open PR from the 2019 Scipy Sprint.