【发布时间】:2018-09-03 12:53:47
【问题描述】:
我正在阅读 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的结果并不完全相同
非常感谢任何信息。如果我应该添加更多细节,请告诉我,谢谢。
【问题讨论】:
标签: machine-learning scikit-learn naivebayes