8000 Stopped warning when alpha=0 for MultinomialNB BernoulliNB · SkuaD01/scikit-learn@c847acf · GitHub
[go: up one dir, main page]

Skip to content

Commit c847acf

Browse files
committed
Stopped warning when alpha=0 for MultinomialNB BernoulliNB
1 parent 70c6ac9 commit c847acf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sklearn/naive_bayes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ class _BaseDiscreteNB(_BaseNB):
487487
_joint_log_likelihood(X) as per _BaseNB
488488
"""
489489

490+
_permit_zero_alpha = False
491+
490492
def _check_X(self, X):
491493
return check_array(X, accept_sparse='csr')
492494

@@ -522,8 +524,9 @@ def _check_alpha(self):
522524
raise ValueError("alpha should be a scalar or a numpy array "
523525
"with shape [n_features]")
524526
if np.min(self.alpha) < _ALPHA_MIN:
525-
warnings.warn('alpha too small will result in numeric errors, '
526-
'setting alpha = %.1e' % _ALPHA_MIN)
527+
if not (self._permit_zero_alpha and self.alpha == 0):
528+
warnings.warn('alpha too small will result in numeric errors, '
529+
'setting alpha = %.1e' % _ALPHA_MIN)
527530
return np.maximum(self.alpha, _ALPHA_MIN)
528531
return self.alpha
529532

@@ -784,6 +787,7 @@ def __init__(self, *, alpha=1.0, fit_prior=True, class_prior=None):
784787
self.alpha = alpha
785788
self.fit_prior = fit_prior
786789
self.class_prior = class_prior
790+
self._permit_zero_alpha = True
787791

788792
def _more_tags(self):
789793
return {'requires_positive_X': True}
@@ -1030,6 +1034,7 @@ def __init__(self, *, alpha=1.0, binarize=.0, fit_prior=True,
10301034
self.binarize = binarize
10311035
self.fit_prior = fit_prior
10321036
self.class_prior = class_prior
1037+
self._permit_zero_alpha = True
10331038

10341039
def _check_X(self, X):
10351040
X = super()._check_X(X)

0 commit comments

Comments
 (0)
0