【问题标题】:Getting feature importance in Naive bayes在朴素贝叶斯中获取特征重要性
【发布时间】:2019-01-28 19:52:10
【问题描述】:

我的问题和这个完全一样, How to get feature Importance in naive bayes?

但是当我运行代码时

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]))

它总是打印具有相同首字母的单词

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

有没有更好的方法可以打印出正负类对应的重要特征?

【问题讨论】:

  • 发布有关您的数据集、问题和完整代码的更多详细信息。是这样,没问题吗?

标签: python machine-learning scikit-learn feature-selection naivebayes


【解决方案1】:

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

【讨论】:

  • 请遵守 StackOverflow 的规则,同时留下响应。谢谢
猜你喜欢
  • 2019-06-04
  • 2018-11-04
  • 2020-11-06
  • 1970-01-01
  • 2015-01-24
  • 2019-04-29
  • 2014-01-03
  • 2012-02-21
  • 2011-12-28
相关资源
最近更新 更多