Skip to content

Commit e4ef854

Browse files
genvalenglemaitreadrinjalaliogriselthomasjpfan
authored
DOC Ensures that BernoulliNB passes numpydoc validation (#20429)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com> Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
1 parent 0d343bb commit e4ef854

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

maint_tools/test_docstrings.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"AffinityPropagation",
1414
"AgglomerativeClustering",
1515
"BaggingRegressor",
16-
"BernoulliNB",
1716
"BernoulliRBM",
1817
"Birch",
1918
"CCA",

sklearn/naive_bayes.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ def predict(self, X):
7171
Parameters
7272
----------
7373
X : array-like of shape (n_samples, n_features)
74+
The input samples.
7475
7576
Returns
7677
-------
7778
C : ndarray of shape (n_samples,)
78-
Predicted target values for X
79+
Predicted target values for X.
7980
"""
8081
check_is_fitted(self)
8182
X = self._check_X(X)
@@ -89,6 +90,7 @@ def predict_log_proba(self, X):
8990
Parameters
9091
----------
9192
X : array-like of shape (n_samples, n_features)
93+
The input samples.
9294
9395
Returns
9496
-------
@@ -111,6 +113,7 @@ def predict_proba(self, X):
111113
Parameters
112114
----------
113115
X : array-like of shape (n_samples, n_features)
116+
The input samples.
114117
115118
Returns
116119
-------
@@ -203,7 +206,7 @@ def __init__(self, *, priors=None, var_smoothing=1e-9):
203206
self.var_smoothing = var_smoothing
204207

205208
def fit(self, X, y, sample_weight=None):
206-
"""Fit Gaussian Naive Bayes according to X, y
209+
"""Fit Gaussian Naive Bayes according to X, y.
207210
208211
Parameters
209212
----------
@@ -576,6 +579,7 @@ def partial_fit(self, X, y, classes=None, sample_weight=None):
576579
Returns
577580
-------
578581
self : object
582+
Returns the instance itself.
579583
"""
580584
first_call = not hasattr(self, "classes_")
581585
X, y = self._check_X_y(X, y, reset=first_call)
@@ -622,7 +626,7 @@ def partial_fit(self, X, y, classes=None, sample_weight=None):
622626
return self
623627

624628
def fit(self, X, y, sample_weight=None):
625-
"""Fit Naive Bayes classifier according to X, y
629+
"""Fit Naive Bayes classifier according to X, y.
626630
627631
Parameters
628632
----------
@@ -639,6 +643,7 @@ def fit(self, X, y, sample_weight=None):
639643
Returns
640644
-------
641645
self : object
646+
Returns the instance itself.
642647
"""
643648
X, y = self._check_X_y(X, y)
644649
_, n_features = X.shape
@@ -1049,18 +1054,13 @@ class BernoulliNB(_BaseDiscreteNB):
10491054
10501055
.. versionadded:: 0.24
10511056
1052-
Examples
1057+
See Also
10531058
--------
1054-
>>> import numpy as np
1055-
>>> rng = np.random.RandomState(1)
1056-
>>> X = rng.randint(5, size=(6, 100))
1057-
>>> Y = np.array([1, 2, 3, 4, 4, 5])
1058-
>>> from sklearn.naive_bayes import BernoulliNB
1059-
>>> clf = BernoulliNB()
1060-
>>> clf.fit(X, Y)
1061-
BernoulliNB()
1062-
>>> print(clf.predict(X[2:3]))
1063-
[3]
1059+
CategoricalNB : Naive Bayes classifier for categorical features.
1060+
ComplementNB : The Complement Naive Bayes classifier
1061+
described in Rennie et al. (2003).
1062+
GaussianNB : Gaussian Naive Bayes (GaussianNB).
1063+
MultinomialNB : Naive Bayes classifier for multinomial models.
10641064
10651065
References
10661066
----------
@@ -1074,6 +1074,19 @@ class BernoulliNB(_BaseDiscreteNB):
10741074
10751075
V. Metsis, I. Androutsopoulos and G. Paliouras (2006). Spam filtering with
10761076
naive Bayes -- Which naive Bayes? 3rd Conf. on Email and Anti-Spam (CEAS).
1077+
1078+
Examples
1079+
--------
1080+
>>> import numpy as np
1081+
>>> rng = np.random.RandomState(1)
1082+
>>> X = rng.randint(5, size=(6, 100))
1083+
>>> Y = np.array([1, 2, 3, 4, 4, 5])
1084+
>>> from sklearn.naive_bayes import BernoulliNB
1085+
>>> clf = BernoulliNB()
1086+
>>> clf.fit(X, Y)
1087+
BernoulliNB()
1088+
>>> print(clf.predict(X[2:3]))
1089+
[3]
10771090
"""
10781091

10791092
def __init__(self, *, alpha=1.0, binarize=0.0, fit_prior=True, class_prior=None):
@@ -1226,7 +1239,7 @@ def __init__(
12261239
self.min_categories = min_categories
12271240

12281241
def fit(self, X, y, sample_weight=None):
1229-
"""Fit Naive Bayes classifier according to X, y
1242+
"""Fit Naive Bayes classifier according to X, y.
12301243
12311244
Parameters
12321245
----------
@@ -1248,6 +1261,7 @@ def fit(self, X, y, sample_weight=None):
12481261
Returns
12491262
-------
12501263
self : object
1264+
Returns the instance itself.
12511265
"""
12521266
return super().fit(X, y, sample_weight=sample_weight)
12531267

@@ -1291,6 +1305,7 @@ def partial_fit(self, X, y, classes=None, sample_weight=None):
12911305
Returns
12921306
-------
12931307
self : object
1308+
Returns the instance itself.
12941309
"""
12951310
return super().partial_fit(X, y, classes, sample_weight=sample_weight)
12961311

0 commit comments

Comments
 (0)