Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

machine learning - Why do I get an IndexError while training a model using CategoricalNB from Naive-Bayes?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...