I am trying to train a CategoricalNB model with the following code. I find all variables to be self-explanatory.
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))
However, while predicting, I get the following error:
/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
I can provide any shape information about the DataFrames(train_split, test_split, etc...) if you require but they are all matching. Can you please help me to find the source of this problem?
Thanks in advance.
question from:
https://stackoverflow.com/questions/65641272/why-do-i-get-an-indexerror-while-training-a-model-using-categoricalnb-from-naive 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…