为什么在使用 Naive-Bayes 中的 CategoricalNB 训练模型时会出现 IndexError?

问题描述

我正在尝试使用以下代码训练 CategoricalNB 模型。我发现所有变量都是不言自明的。

from sklearn.naive_bayes import CategoricalNB

cnb = CategoricalNB()
cnb.fit(train_split,train_split_label)

cnb_preds = cnb.predict(test_split)

print('test_CNB: ',accuracy_score(test_split_label,cnb_preds))

但是,在预测时,我收到以下错误

/usr/local/lib/python3.6/dist-packages/sklearn/naive_bayes.py in _joint_log_likelihood(self,X)
   1217         for i in range(self.n_features_):
   1218             indices = X[:,i]
-> 1219             jll += self.feature_log_prob_[i][:,indices].T
   1220         total_ll = jll + self.class_log_prior_
   1221         return total_ll

IndexError: index 1 is out of bounds for axis 1 with size 1

如果您需要,我可以提供有关 DataFrames(train_split、test_split 等...)的任何形状信息,但它们都是匹配的。你能帮我找到这个问题的根源吗?

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)