BernoulliNB 在 sklearn 包中使用什么方法进行预测?
what is the approach used by BernoulliNB in sklearn package for prediction?
我正在阅读 Sklearn 中朴素贝叶斯的实现,但我无法理解 BernoulliNB 的预测部分:
代码借自source
def _joint_log_likelihood(self, X):
#.. some code ommited
neg_prob = np.log(1 - np.exp(self.feature_log_prob_))
# Compute neg_prob · (1 - X).T as ∑neg_prob - X · neg_prob
jll = safe_sparse_dot(X, (self.feature_log_prob_ - neg_prob).T)
jll += self.class_log_prior_ + neg_prob.sum(axis=1)
return jll
neg_prob
在这里面的作用是什么。有人可以解释这种方法吗?
我在任何地方在线阅读 (source) 简单的方法是:
For word in document:
For class in all_class:
class_prob[class] += np.log(class_prob_for[word])
# basically add up the log probability of word given that class.
# (Which is pre computed from training data)
# finally add up the log probability of the class itself.
For class in all_class:
class_prob[class] += np.log(class_prob_for[class])
但这并没有给出与 BernoulliNB
完全相同的结果
非常感谢任何信息。如果我应该添加更多详细信息,请告诉我,谢谢。
发现 BernoulliNB
与 MultinomialNB
略有不同。
如此处解释:http://blog.datumbox.com/machine-learning-tutorial-the-naive-bayes-text-classifier/
文档中未出现的术语也用作:(1 - conditional_probability_of_term_in_class)
The Bernoulli variation, as described by Manning et al (2008),
generates a Boolean indicator about each term of the vocabulary equal
to 1 if the term belongs to the examining document and 0 if it does
not. The model of this variation is significantly different from
Multinomial not only because it does not take into consideration the
number of occurrences of each word, but also because it takes into
account the non-occurring terms within the document. While in
Multinomial model the non-occurring terms are completely ignored, in
Bernoulli model they are factored when computing the conditional
probabilities and thus the absence of terms is taken into account.
sklearn 中使用的算法来源:https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
我正在阅读 Sklearn 中朴素贝叶斯的实现,但我无法理解 BernoulliNB 的预测部分:
代码借自source
def _joint_log_likelihood(self, X):
#.. some code ommited
neg_prob = np.log(1 - np.exp(self.feature_log_prob_))
# Compute neg_prob · (1 - X).T as ∑neg_prob - X · neg_prob
jll = safe_sparse_dot(X, (self.feature_log_prob_ - neg_prob).T)
jll += self.class_log_prior_ + neg_prob.sum(axis=1)
return jll
neg_prob
在这里面的作用是什么。有人可以解释这种方法吗?
我在任何地方在线阅读 (source) 简单的方法是:
For word in document:
For class in all_class:
class_prob[class] += np.log(class_prob_for[word])
# basically add up the log probability of word given that class.
# (Which is pre computed from training data)
# finally add up the log probability of the class itself.
For class in all_class:
class_prob[class] += np.log(class_prob_for[class])
但这并没有给出与 BernoulliNB
非常感谢任何信息。如果我应该添加更多详细信息,请告诉我,谢谢。
发现 BernoulliNB
与 MultinomialNB
略有不同。
如此处解释:http://blog.datumbox.com/machine-learning-tutorial-the-naive-bayes-text-classifier/
文档中未出现的术语也用作:(1 - conditional_probability_of_term_in_class)
The Bernoulli variation, as described by Manning et al (2008), generates a Boolean indicator about each term of the vocabulary equal to 1 if the term belongs to the examining document and 0 if it does not. The model of this variation is significantly different from Multinomial not only because it does not take into consideration the number of occurrences of each word, but also because it takes into account the non-occurring terms within the document. While in Multinomial model the non-occurring terms are completely ignored, in Bernoulli model they are factored when computing the conditional probabilities and thus the absence of terms is taken into account.
sklearn 中使用的算法来源:https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html