2

My problem is exactly similar to this, How to get feature Importance in naive bayes?

but when I run the code

neg_class_prob_sorted = NB_optimal.feature_log_prob_[0, :].argsort()
pos_class_prob_sorted = NB_optimal.feature_log_prob_[1, :].argsort()

print(np.take(count_vect.get_feature_names(), neg_class_prob_sorted[:10]))
print(np.take(count_vect.get_feature_names(), pos_class_prob_sorted[:10]))

it always prints words with same initials

['aafco' 'misfit' 'misfir' 'miseri' 'miser' 'misconcept' 'miscarriag'
 'misc' 'mirin' 'minuscul']
['aafco' 'metrx' 'meticul' 'methood' 'metaplus' 'metaphor' 'mestemach'
 'messiest' 'mesmer' 'mesa']

Is there any better way I can print the important features corrosponding to positive and negative class?

Alan
  • 61
  • 2
  • 6

1 Answers1

0

important_features= pd.DataFrame(data=np.transpose(model.fit(fdata, y_train).feature_log_prob_).astype("float32"),index=fdata.columns)