如何计算伯努利朴素贝叶斯的联合对数似然

问题描述 投票:0回答:2

对于使用 BernoulliNB 的分类问题,如何计算联合对数似然。联合似然由以下公式计算,其中 y(d) 是实际输出数组(不是预测值),x(d) 是特征数据集。

我阅读了this answer并阅读了documentation但它并没有完全达到我的目的。有人可以吗 帮助。

machine-learning scikit-learn naivebayes bernoulli-probability
2个回答
1
投票

通过查看代码,在计算联合对数似然的 BernoulliNB 中似乎有一个隐藏的未记录的

._joint_log_likelihood(self, X)
函数。

它的实现与您的要求有些一致。


1
投票
- The solution is to count the positive input variables of the 
  positive output function.
- We achieve this by counting the 
  positive output variables or y of index y or y of 1 or y[1] or 
  data[idx][1].

- The first block of code is the **training** and *learning* of the 
  w, x, and can be y and z 
  with respect to the horizontal movement, vertical movement, 
  and diagonal movement and the time movement by thinking
  and solving the joint log likelihood program
  or algorithm or function or method to visualize or look or see the 
  positive or reality or real building blocks of engineering or 
  science or products or services to create money or profit or 
  revenue.
- The second block of code is the **testing** and *counting* of the 
  accepted or passed positive or reality or real numbers of the 
  customer by counting the revenue or money or profit or work to 
  satisfy the customers and yourself.

- train, test, train_labels, test_labels = train_test_split(Xs[0], 
  ys[0], test_size=1./3, random_state=r)
  naive = BernoulliNB(alpha= 10**-7)
  model = naive.fit(train, train_labels)
  joint_log_train = model._joint_log_likelihood(train)
- l = [np.append(x,y) for x, y in zip(train, train_labels)]

- # Write your code below this line.
- def count(data, label):
    x = 0
    for idx, l in enumerate(label):
        if (l == True):
            x += data[idx][1]
        else:
            x += data[idx][0]
    return x
- for i, (x, y) in enumerate(zip(Xs, ys)):
    train, test, train_labels, test_labels = train_test_split(x, y, 
    test_size=1./3, random_state=r)
    for j, a in enumerate(alphas):   
        naive = BernoulliNB(alpha = a)
        model = naive.fit(train, train_labels)
        joint_log_train = model._joint_log_likelihood(train)
        joint_log_test = model._joint_log_likelihood(test)
        train_jil[i][j] = count(joint_log_train, train_labels)
        test_jil[i][j] = count(joint_log_test, test_labels)
© www.soinside.com 2019 - 2024. All rights reserved.