原型
class sklearn.naive_bayes.
MultinomialNB
(alpha=1.0, fit_prior=True, class_prior=None)
参数
Parameters: |
alpha : float, optional (default=1.0)
fit_prior : boolean, optional (default=True)
class_prior : array-like, size (n_classes,), optional (default=None)
|
---|
alpha的说明——
The parameters is estimated by a smoothed version of maximum likelihood, i.e. relative frequency counting:
where is the number of times feature
appears in a sample of class
in the training set
, and
is the total count of all features for class
.
The smoothing priors accounts for features not present in the learning samples and prevents zero probabilities in further computations. Setting
is called Laplace smoothing, while
is called Lidstone smoothing.
示例
>>> import numpy as np >>> X = np.random.randint(5, size=(6, 100)) >>> y = np.array([1, 2, 3, 4, 5, 6]) >>> from sklearn.naive_bayes import MultinomialNB >>> clf = MultinomialNB() >>> clf.fit(X, y) MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True) >>> print(clf.predict(X[2:3]))