@@ -487,6 +487,8 @@ class _BaseDiscreteNB(_BaseNB):
487
487
_joint_log_likelihood(X) as per _BaseNB
488
488
"""
489
489
490
+ _permit_zero_alpha = False
491
+
490
492
def _check_X (self , X ):
491
493
return check_array (X , accept_sparse = 'csr' )
492
494
@@ -522,8 +524,9 @@ def _check_alpha(self):
522
524
raise ValueError ("alpha should be a scalar or a numpy array "
523
525
"with shape [n_features]" )
524
526
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 )
527
530
return np .maximum (self .alpha , _ALPHA_MIN )
528
531
return self .alpha
529
532
@@ -784,6 +787,7 @@ def __init__(self, *, alpha=1.0, fit_prior=True, class_prior=None):
784
787
self .alpha = alpha
785
788
self .fit_prior = fit_prior
786
789
self .class_prior = class_prior
790
+ self ._permit_zero_alpha = True
787
791
788
792
def _more_tags (self ):
789
793
return {'requires_positive_X' : True }
@@ -1030,6 +1034,7 @@ def __init__(self, *, alpha=1.0, binarize=.0, fit_prior=True,
1030
1034
self .binarize = binarize
1031
1035
self .fit_prior = fit_prior
1032
1036
self .class_prior = class_prior
1037
+ self ._permit_zero_alpha = True
1033
1038
1034
1039
def _check_X (self , X ):
1035
1040
X = super ()._check_X (X )
0 commit comments