目前正在实现朴素贝叶斯算法,在预测时遇到关键错误:0。我有一个检查,所以我不知道为什么这个错误出现在 classprob[i] 行
def predict_prob(sentence, prior, likelyhood):
class_prob = np.zeros((len(prior)))
for i in range(len(prior)):
likelyhood_prod = 1
for word in sentence:
if not word in likelyhood:
likelyhood_prod = 0
break
likelyhood_prod *= likelyhood[word][i]
class_prob[i] = prior[i] * likelyhood_prod
print (class_prob)
return np.argmax(class_prob)