8000 DOC improve naive_bayes.py documentation (#15943) · scikit-learn/scikit-learn@bbb21e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit bbb21e2

Browse files
Reshama Shaikhjigna-panchal
authored andcommitted
DOC improve naive_bayes.py documentation (#15943)
Co-authored-by: Jigna Panchal <40188288+jigna-panchal@users.noreply.github.com>
1 parent 1cda8ed commit bbb21e2
File tree

1 file changed

+63
-64
lines changed

1 file changed

+63
-64
lines changed

sklearn/naive_bayes.py

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,23 @@ class GaussianNB(_BaseNB):
139139
140140
Attributes
141141
----------
142-
class_prior_ : array, shape (n_classes,)
143-
probability of each class.
144-
145142
class_count_ : array, shape (n_classes,)
146143
number of training samples observed in each class.
147144
145+
class_prior_ : array, shape (n_classes,)
146+
probability of each class.
147+
148148
classes_ : array, shape (n_classes,)
149149
class labels known to the classifier
150150
151-
theta_ : array, shape (n_classes, n_features)
152-
mean of each feature per class
151+
epsilon_ : float
152+
absolute additive value to variances
153153
154154
sigma_ : array, shape (n_classes, n_features)
155155
variance of each feature per class
156156
157-
epsilon_ : float
158-
absolute additive value to variances
157+
theta_ : array, shape (n_classes, n_features)
158+
mean of each feature per class
159159
160160
Examples
161161
--------
@@ -685,33 +685,33 @@ class MultinomialNB(_BaseDiscreteNB):
685685
686686
Attributes
687687
----------
688+
class_count_ : array, shape (n_classes,)
689+
Number of samples encountered for each class during fitting. This
690+
value is weighted by the sample weight when provided.
691+
688692
class_log_prior_ : array, shape (n_classes, )
689693
Smoothed empirical log probability for each class.
690694
691-
intercept_ : array, shape (n_classes, )
692-
Mirrors ``class_log_prior_`` for interpreting MultinomialNB
693-
as a linear model.
694-
695-
feature_log_prob_ : array, shape (n_classes, n_features)
696-
Empirical log probability of features
697-
given a class, ``P(x_i|y)``.
695+
classes_ : array, shape (n_classes,)
696+
Class labels known to the classifier
698697
699698
coef_ : array, shape (n_classes, n_features)
700699
Mirrors ``feature_log_prob_`` for interpreting MultinomialNB
701700
as a linear model.
702701
703-
class_count_ : array, shape (n_classes,)
704-
Number of samples encountered for each class during fitting. This
705-
value is weighted by the sample weight when provided.
706-
707-
classes_ : array, shape (n_classes,)
708-
Class labels known to the classifier
709-
710702
feature_count_ : array, shape (n_classes, n_features)
711703
Number of samples encountered for each (class, feature)
712704
during fitting. This value is weighted by the sample weight when
713705
provided.
714706
707+
feature_log_prob_ : array, shape (n_classes, n_features)
708+
Empirical log probability of features
709+
given a class, ``P(x_i|y)``.
710+
711+
intercept_ : array, shape (n_classes, )
712+
Mirrors ``class_log_prior_`` for interpreting MultinomialNB
713+
as a linear model.
714+
715715
n_features_ : int
716716
Number of features of each sample.
717717
@@ -797,31 +797,31 @@ class ComplementNB(_BaseDiscreteNB):
797797
798798
Attributes
799799
----------
800-
class_log_prior_ : array, shape (n_classes, )
801-
Smoothed empirical log probability for each class. Only used in edge
802-
case with a single class in the training set.
803-
804-
feature_log_prob_ : array, shape (n_classes, n_features)
805-
Empirical weights for class complements.
806-
807800
class_count_ : array, shape (n_classes,)
808801
Number of samples encountered for each class during fitting. This
809802
value is weighted by the sample weight when provided.
810803
804+
class_log_prior_ : array, shape (n_classes, )
805+
Smoothed empirical log probability for each class. Only used in edge
806+
case with a single class in the training set.
807+
811808
classes_ : array, shape (n_classes,)
812809
Class labels known to the classifier
813810
811+
feature_all_ : array, shape (n_features,)
812+
Number of samples encountered for each feature during fitting. This
813+
value is weighted by the sample weight when provided.
814+
814815
feature_count_ : array, shape (n_classes, n_features)
815816
Number of samples encountered for each (class, feature) during fitting.
816817
This value is weighted by the sample weight when provided.
817818
819+
feature_log_prob_ : array, shape (n_classes, n_features)
820+
Empirical weights for class complements.
821+
818822
n_features_ : int
819823
Number of features of each sample.
820824
821-
feature_all_ : array, shape (n_features,)
822-
Number of samples encountered for each feature during fitting. This
823-
value is weighted by the sample weight when provided.
824-
825825
Examples
826826
--------
827827
>>> import numpy as np
@@ -909,16 +909,13 @@ class BernoulliNB(_BaseDiscreteNB):
909909
910910
Attributes
911911
----------
912-
class_log_prior_ : array, shape = [n_classes]
913-
Log probability of each class (smoothed).
914-
915-
feature_log_prob_ : array, shape = [n_classes, n_features]
916-
Empirical log probability of features given a class, P(x_i|y).
917-
918912
class_count_ : array, shape = [n_classes]
919913
Number of samples encountered for each class during fitting. This
920914
value is weighted by the sample weight when provided.
921915
916+
class_log_prior_ : array, shape = [n_classes]
917+
Log probability of each class (smoothed).
918+
922919
classes_ : array, shape (n_classes,)
923920
Class labels known to the classifier
924921
@@ -927,26 +924,12 @@ class BernoulliNB(_BaseDiscreteNB):
927924
during fitting. This value is weighted by the sample weight when
928925
provided.
929926
927+
feature_log_prob_ : array, shape = [n_classes, n_features]
928+
Empirical log probability of features given a class, P(x_i|y).
929+
930930
n_features_ : int
931931
Number of features of each sample.
932932
933-
See Also
934-
----------
935-
MultinomialNB: The multinomial Naive Bayes classifier is \
936-
suitable for classification with discrete features.
937-
938-
References
939-
----------
940-
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to
941-
Information Retrieval. Cambridge University Press, pp. 234-265.
942-
https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
943-
944-
A. McCallum and K. Nigam (1998). A comparison of event models for naive
945-
Bayes text classification. Proc. AAAI/ICML-98 Workshop on Learning for
946-
Text Categorization, pp. 41-48.
947-
948-
V. Metsis, I. Androutsopoulos and G. Paliouras (2006). Spam filtering with
949-
naive Bayes -- Which naive Bayes? 3rd Conf. on Email and Anti-Spam (CEAS).
950933
951934
Examples
952935
--------
@@ -960,6 +943,19 @@ class BernoulliNB(_BaseDiscreteNB):
960943
BernoulliNB()
961944
>>> print(clf.predict(X[2:3]))
962945
[3]
946+
947+
References
948+
----------
949+
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to
950+
Information Retrieval. Cambridge University Press, pp. 234-265.
951+
https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
952+
953+
A. McCallum and K. Nigam (1998). A comparison of event models for naive
954+
Bayes text classification. Proc. AAAI/ICML-98 Workshop on Learning for
955+
Text Categorization, pp. 41-48.
956+
957+
V. Metsis, I. Androutsopoulos and G. Paliouras (2006). Spam filtering with
958+
naive Bayes -- Which naive Bayes? 3rd Conf. on Email and Anti-Spam (CEAS).
963959
"""
964960

965961
def __init__(self, alpha=1.0, binarize=.0, fit_prior=True,
@@ -1036,22 +1032,25 @@ class CategoricalNB(_BaseDiscreteNB):
10361032
10371033
Attributes
10381034
----------
1039-
class_log_prior_ : array, shape (n_classes, )
1040-
Smoothed empirical log probability for each class.
1041-
1042-
feature_log_prob_ : list of arrays, len n_features
1035+
category_count_ : list of arrays, len n_features
10431036
Holds arrays of shape (n_classes, n_categories of respective feature)
1044-
for each feature. Each array provides the empirical log probability
1045-
of categories given the respective feature and class, ``P(x_i|y)``.
1037+
for each feature. Each array provides the number of samples
1038+
encountered for each class and category of the specific feature.
10461039
10471040
class_count_ : array, shape (n_classes,)
10481041
Number of samples encountered for each class during fitting. This
10491042
value is weighted by the sample weight when provided.
10501043
1051-
category_count_ : list of arrays, len n_features
1044+
class_log_prior_ : array, shape (n_classes, )
1045+
Smoothed empirical log probability for each class.
1046+
1047+
classes_ : array, shape (n_classes,)
1048+
Class labels known to the classifier
1049+
1050+
feature_log_prob_ : list of arrays, len n_features
10521051
Holds arrays of shape (n_classes, n_categories of respective feature)
1053-
for each feature. Each array provides the number of samples
1054-
encountered for each class and category of the specific feature.
1052+
for each feature. Each array provides the empirical log probability
1053+
of categories given the respective feature and class, ``P(x_i|y)``.
10551054
10561055
n_features_ : int
10571056
Number of features of each sample.

0 commit comments

Comments
 (0)
0