Skip to content

[MRG] Adding variable force_alpha to classes in naive_bayes.py - #18805

Closed
hongshaoyang wants to merge 39 commits into
scikit-learn:mainfrom
hongshaoyang:10772-force-alpha
Closed

hongshaoyang wants to merge 39 commits into
scikit-learn:mainfrom
hongshaoyang:10772-force-alpha

Conversation

@hongshaoyang

@hongshaoyang hongshaoyang commented Nov 10, 2020 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Gentle ping @cmarmo @jnothman @amueller

@cmarmo

cmarmo commented Dec 18, 2020

Copy link
Copy Markdown
Contributor

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

@jjerphan jjerphan left a comment

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.

I am catching up with this PR.
I just have one last suggestion prior to the merge.

Comment thread sklearn/naive_bayes.py Resolved
@jjerphan

jjerphan commented Jun 9, 2021 •

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

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

@jjerphan

jjerphan commented Jun 23, 2021 •

Copy link
Copy Markdown
Member

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

@jjerphan jjerphan left a comment •

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.

LGTM @hongshaoyang. 👍

I just have one last suggestion.

Comment thread sklearn/tests/test_naive_bayes.py Resolved
Co-authored-by: Julien Jerphanion <[email protected]>
@cmarmo

cmarmo commented Nov 12, 2021

Copy link
Copy Markdown
Contributor

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!

@TomDLT TomDLT left a comment

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.

Some comments.

Main question: Do we really need to warn when the user explicitly set force_alpha=True ?

Comment thread doc/whats_new/v1.0.rst
: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
Copy Markdown
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
Copy Markdown
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.

Comment thread doc/whats_new/v1.0.rst
- |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
Copy Markdown
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.

Comment thread sklearn/naive_bayes.py

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

Comment thread sklearn/naive_bayes.py
`_ALPHA_MIN`. If True, warn user about potential numeric errors
and proceed with alpha unchanged.

.. versionadded:: 1.0

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.

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

Comment thread doc/whats_new/v1.0.rst

:mod:`sklearn.naive_bayes`
..........................
- |Fix| A new parameter `force_alpha` was added to :class:`BernoulliNB` and

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.

Because v1.0 is already released, this entry should now be moved to v1.1.rst.

Comment thread sklearn/naive_bayes.py
)
return np.maximum(self.alpha, _ALPHA_MIN)
if self.force_alpha:
warnings.warn(

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.

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.

Comment thread sklearn/naive_bayes.py
`_ALPHA_MIN`. If True, warn user about potential numeric errors
and proceed with alpha unchanged.

.. versionadded:: 1.0

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.

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

Comment thread sklearn/naive_bayes.py
`_ALPHA_MIN`. If True, warn user about potential numeric errors
and proceed with alpha unchanged.

.. versionadded:: 1.0

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.

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

Comment thread sklearn/naive_bayes.py
`_ALPHA_MIN`. If True, warn user about potential numeric errors
and proceed with alpha unchanged.

.. versionadded:: 1.0

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.

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

Comment thread sklearn/naive_bayes.py
)
else:
warnings.warn(
"alpha too small will result in numeric errors, "

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.

I would add something like "use force_alpha=True to keep alpha unchanged.".

@Micky774

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

cmarmo commented Jul 9, 2022

Copy link
Copy Markdown
Contributor

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