-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] Adding variable force_alpha to classes in naive_bayes.py #18805
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
Conversation
Merging changes from the main repository
Merging changes from the main repository
Merging changes from the main repository
Update branch
…-update Resolving conflicts
…ka204/scikit-learn into alpha-close-or-equal-0-update
…-update Alpha close or equal 0 update
Update master
…a-is-close-or-equal-0' into master-copy
Update branch
…ernoulliNB-and-MultinomialNB-when-alpha-is-close-or-equal-0 # Conflicts: # doc/whats_new/v0.24.rst # sklearn/naive_bayes.py
4b1802a
to
06f6779
Compare
06f6779
to
2d16091
Compare
Hi @hongshaoyang , sorry your pull request didn't make it in 0.24. Do you mind moving your what's new entry from v0.24.rst to v1.0.rst? Thanks! |
# Conflicts: # doc/whats_new/v1.0.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am catching up with this PR.
I just have one last suggestion prior to the merge.
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Small tip: I would suggest to both make modifications and run tests locally prior to pushing new commits. This would allow you better take suggestions into account, group suggestions (if relevant) and assert if you've missed something (as suggestions sometimes necessitate other patches than theirs) without going back and forth with the CI logs. 🙂 |
Thank you! I was eager to commit the suggestions without taking tests into account. Your suggestion is helpful! |
Hi @hongshaoyang, In the meantime, black code formatting was set on Instructions given in #20301 (comment) might help you with resolving them. Let's then merge it once resolved. 🙂 |
# Conflicts: # sklearn/naive_bayes.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @hongshaoyang. 👍
I just have one last suggestion.
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Hi @hongshaoyang, and thanks for your patience. If you are still motivated, this PR could be a nice fix for version 1.1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments.
Main question: Do we really need to warn when the user explicitly set force_alpha=True
?
@@ -462,6 +462,11 @@ Changelog | |||
|
|||
:mod:`sklearn.naive_bayes` | |||
.......................... | |||
- |Fix| A new parameter `force_alpha` was added to :class:`BernoulliNB` and | |||
class:`MultinomialNB`, allowing user to set parameter alpha to a very |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class:`MultinomialNB`, allowing user to set parameter alpha to a very | |
:class:`MultinomialNB`, allowing user to set parameter alpha to a very |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to mention ComplementNB
and CategoricalNB
.
- |Fix| A new parameter `force_alpha` was added to :class:`BernoulliNB` and | ||
class:`MultinomialNB`, allowing user to set parameter alpha to a very | ||
small number, greater or equal 0, which was earlier automatically changed | ||
to `_ALPHA_MIN` instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change _ALPHA_MIN
into its value to be more informative.
|
||
force_alpha : bool, default=False | ||
If False and alpha is too close to 0, it will set alpha to | ||
`_ALPHA_MIN`. If True, warn user about potential numeric errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change _ALPHA_MIN
into its value to be more informative.
`_ALPHA_MIN`. If True, warn user about potential numeric errors | ||
and proceed with alpha unchanged. | ||
|
||
.. versionadded:: 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. versionadded:: 1.0 | |
.. versionadded:: 1.1 |
@@ -462,6 +462,11 @@ Changelog | |||
|
|||
:mod:`sklearn.naive_bayes` | |||
.......................... | |||
- |Fix| A new parameter `force_alpha` was added to :class:`BernoulliNB` and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because v1.0 is already released, this entry should now be moved to v1.1.rst
.
) | ||
return np.maximum(self.alpha, _ALPHA_MIN) | ||
if self.force_alpha: | ||
warnings.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really useful to warn when the user specifically set the parameter force_alpha=True
? I would remove the warning and improve the docstring to mention potential numerical errors.
`_ALPHA_MIN`. If True, warn user about potential numeric errors | ||
and proceed with alpha unchanged. | ||
|
||
.. versionadded:: 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. versionadded:: 1.0 | |
.. versionadded:: 1.1 |
`_ALPHA_MIN`. If True, warn user about potential numeric errors | ||
and proceed with alpha unchanged. | ||
|
||
.. versionadded:: 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. versionadded:: 1.0 | |
.. versionadded:: 1.1 |
`_ALPHA_MIN`. If True, warn user about potential numeric errors | ||
and proceed with alpha unchanged. | ||
|
||
.. versionadded:: 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. versionadded:: 1.0 | |
.. versionadded:: 1.1 |
) | ||
else: | ||
warnings.warn( | ||
"alpha too small will result in numeric errors, " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add something like "use force_alpha=True to keep alpha unchanged.".
Picked up in PR #22269 |
Closing this as superseded by #22269 . |
Reference Issues/PRs
Fixes #10772
References PR #9131
References PR #10775
Taking over stalled PR #16747
What does this implement/fix? Explain your changes.
This PR takes over stalled PR #16747.
From the description of #16747: "This PR adds a new variable alphaCorrection in classes in naive_bayes.py, which is set to True by default and if set to False, then for alpha=0 (or greater, but still smaller than _ALPHA_MIN) alpha is not being rounded up to _ALPHA_MIN."
I merged master and fixed conflicts, no other changes.
Any other comments?
#16747 (comment) should be resolved.