8000 [MRG] Adding variable force_alpha to classes in naive_bayes.py by hongshaoyang · Pull Request #18805 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 39 commits into from

Conversation

hongshaoyang
Copy link
Contributor
@hongshaoyang hongshaoyang commented Nov 10, 2020

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.

arka204 and others added 18 commits March 22, 2020 11:06
Merging changes from the main repository
Merging changes from the main repository
Merging changes from the main repository
…ernoulliNB-and-MultinomialNB-when-alpha-is-close-or-equal-0

# Conflicts:
#	doc/whats_new/v0.24.rst
#	sklearn/naive_bayes.py
@hongshaoyang
Copy link
Contributor Author

Gentle ping @cmarmo @jnothman @amueller

@cmarmo
Copy link
Contributor
cmarmo commented Dec 18, 2020

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!

Base automatically changed from master to main January 22, 2021 10:53
@hongshaoyang hongshaoyang changed the title [MRG] Adding variable alphaCorrection to classes in naive_bayes.py [MRG] Adding variable force_alpha to classes in naive_bayes.py May 29, 2021
Copy link
Member
@jjerphan jjerphan left a 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.

@jjerphan
Copy link
Member
jjerphan commented Jun 9, 2021

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. 🙂

@hongshaoyang
Copy link
Contributor Author

Thank you! I was eager to commit the suggestions without taking tests into account. Your suggestion is helpful!

@jjerphan
Copy link
Member
jjerphan commented Jun 23, 2021

Hi @hongshaoyang,

In the meantime, black code formatting was set on main, causing conflict on this branch.

Instructions given in #20301 (comment) might help you with resolving them.

Let's then merge it once resolved. 🙂

Copy link
Member
@jjerphan jjerphan left a 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>
@cmarmo
Copy link
Contributor
cmarmo commented Nov 12, 2021

Hi @hongshaoyang, and thanks for your patience. If you are still motivated, this PR could be a nice fix for version 1.1.
Do you mind fixing conflicts and updating the version number to 1.1? Then let's see if perhaps @TomDLT might be available for a quick review? Thanks!

Copy link
Member
@TomDLT TomDLT left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class:`MultinomialNB`, allowing user to set parameter alpha to a very
:class:`MultinomialNB`, allowing user to set parameter alpha to a very

Copy link
Member

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.
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 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
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 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.. 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
Copy link
Member

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(
Copy link
Member

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

Choose a reason for hiding this comment

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

Suggested change
.. versionadded:: 1.0
.. versionadded:: 1.1

`_ALPHA_MIN`. If True, warn user about potential numeric errors
and proceed with alpha unchanged.

.. versionadded:: 1.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.. versionadded:: 1.0
.. versionadded:: 1.1

`_ALPHA_MIN`. If True, warn user about potential numeric errors
and proceed with alpha unchanged.

.. versionadded:: 1.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.. versionadded:: 1.0
.. versionadded:: 1.1

)
else:
warnings.warn(
"alpha too small will result in numeric errors, "
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 add something like "use force_alpha=True to keep alpha unchanged.".

@Micky774
Copy link
Contributor

Picked up in PR #22269

@cmarmo cmarmo added Superseded PR has been replace by a newer PR and removed Stalled help wanted labels Jan 22, 2022
@cmarmo
Copy link
Contributor
cmarmo commented Jul 9, 2022

Closing this as superseded by #22269 .

@cmarmo cmarmo closed this Jul 9, 2022
@hongshaoyang hongshaoyang deleted the 10772-force-alpha branch July 30, 2022 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:naive_bayes Superseded PR has been replace by a newer PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BernoulliNB and MultinomialNB documentation for alpha=0
7 participants
0