Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d785179

Browse filesBrowse files
avm19thomasjpfan
andcommitted
DOC Clarifies comments and docstrings in _BaseDiscreteNB (scikit-learn#22565)
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
1 parent a8610c4 commit d785179
Copy full SHA for d785179

File tree

1 file changed

+14
-8
lines changed
Filter options

1 file changed

+14
-8
lines changed

‎sklearn/naive_bayes.py

Copy file name to clipboardExpand all lines: sklearn/naive_bayes.py
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def _joint_log_likelihood(self, X):
5353
I.e. ``log P(c) + log P(x|c)`` for all rows x of X, as an array-like of
5454
shape (n_samples, n_classes).
5555
56-
Input is passed to _joint_log_likelihood as-is by predict,
57-
predict_proba and predict_log_proba.
56+
predict, predict_proba, and predict_log_proba pass the input through
57+
_check_X and handle it over to _joint_log_likelihood.
5858
"""
5959

6060
@abstractmethod
@@ -140,7 +140,7 @@ class GaussianNB(_BaseNB):
140140
Parameters
141141
----------
142142
priors : array-like of shape (n_classes,)
143-
Prior probabilities of the classes. If specified the priors are not
143+
Prior probabilities of the classes. If specified, the priors are not
144144
adjusted according to the data.
145145
146146
var_smoothing : float, default=1e-9
@@ -423,13 +423,13 @@ def _partial_fit(self, X, y, classes=None, _refit=False, sample_weight=None):
423423
# Take into account the priors
424424
if self.priors is not None:
425425
priors = np.asarray(self.priors)
426-
# Check that the provide prior match the number of classes
426+
# Check that the provided prior matches the number of classes
427427
if len(priors) != n_classes:
428428
raise ValueError("Number of priors must match number of classes.")
429429
# Check that the sum is 1
430430
if not np.isclose(priors.sum(), 1.0):
431431
raise ValueError("The sum of the priors should be 1.")
432-
# Check that the prior are non-negative
432+
# Check that the priors are non-negative
433433
if (priors < 0).any():
434434
raise ValueError("Priors must be non-negative.")
435435
self.class_prior_ = priors
@@ -523,6 +523,12 @@ def _check_X_y(self, X, y, reset=True):
523523
return self._validate_data(X, y, accept_sparse="csr", reset=reset)
524524

525525
def _update_class_log_prior(self, class_prior=None):
526+
"""Update class log priors.
527+
528+
The class log priors are based on `class_prior`, class count or the
529+
number of classes. This method is called each time `fit` or
530+
`partial_fit` update the model.
531+
"""
526532
n_classes = len(self.classes_)
527533
if class_prior is not None:
528534
if len(class_prior) != n_classes:
@@ -733,7 +739,7 @@ class MultinomialNB(_BaseDiscreteNB):
733739
If false, a uniform prior will be used.
734740
735741
class_prior : array-like of shape (n_classes,), default=None
736-
Prior probabilities of the classes. If specified the priors are not
742+
Prior probabilities of the classes. If specified, the priors are not
737743
adjusted according to the data.
738744
739745
Attributes
@@ -988,7 +994,7 @@ class BernoulliNB(_BaseDiscreteNB):
988994
If false, a uniform prior will be used.
989995
990996
class_prior : array-like of shape (n_classes,), default=None
991-
Prior probabilities of the classes. If specified the priors are not
997+
Prior probabilities of the classes. If specified, the priors are not
992998
adjusted according to the data.
993999
9941000
Attributes
@@ -1136,7 +1142,7 @@ class CategoricalNB(_BaseDiscreteNB):
11361142
If false, a uniform prior will be used.
11371143
11381144
class_prior : array-like of shape (n_classes,), default=None
1139-
Prior probabilities of the classes. If specified the priors are not
1145+
Prior probabilities of the classes. If specified, the priors are not
11401146
adjusted according to the data.
11411147
11421148
min_categories : int or array-like of shape (n_features,), default=None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.