【问题标题】:what is the approach used by BernoulliNB in sklearn package for prediction?BernoulliNB 在 sklearn 包中用于预测的方法是什么?
【发布时间】: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


    【解决方案1】:

    发现BernoulliNB MultinomialNB @。

    如此所述:http://blog.datumbox.com/machine-learning-tutorial-the-naive-bayes-text-classifier/

    在文档中不发生的术语也被用作:(1 - conditional_probability_of_term_in_class)

    Bernoulli变异,如Manning等人(2008)所述, 关于词汇量等于的每个术语,生成布尔指示符 如果该术语属于检查文件,则为0 不是。这种变化的模型与 多项式不仅因为它没有考虑到 每个单词的出现次数,还因为它需要 帐户在文档中的未发生术语。而在 多项式模型未发生的术语完全忽略 伯努利模型它们是在计算条件时的因素 概率并因此考虑缺乏术语。

    在Sklearn源中使用的algo:https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html

    【讨论】:

      猜你喜欢
      • 2019-12-27
      • 2023-03-12
      • 2020-02-26
      • 2020-11-13
      • 1970-01-01
      • 2017-03-05
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多