2

I use MultinomialNB() classifier and TfidfVectorizer to build a binary model (have only 2 classes) I want to print out and save to csv file the complete list of coef_ , features and labels. What happens is I can print out features for one class only- it gives an error once i try to print for the second class. I understand it is because of the classes being binary? i have used the following code

index = 0 coef_features_c1_c2 = []

for feat, c1, c2 in zip(vector.get_feature_names(), clf.feature_count_[0], clf.feature_count_[1]): coef_features_c1_c2.append(tuple([clf.coef_[0][index], feat, c1, c2])) index+=1

for i in sorted(coef_features_c1_c2): print (i)

How to get most informative features for scikit-learn classifier for different class?

my question is how to get all the features for both classes

Thank you

Community
  • 1
  • 1

0 Answers0