【问题标题】:How to get feature names corresponding to scores for chi square feature selection in scikit如何在 scikit 中获取与卡方特征选择分数对应的特征名称
【发布时间】:2015-05-04 07:01:57
【问题描述】:

我正在使用 Scikit 进行特征选择,但我想获取文本中所有 unigram 的得分值。我得到了分数,但我如何将它们映射到实际的特征名称。

from sklearn.feature_extraction.text  import CountVectorizer
from sklearn.feature_selection import  SelectKBest, chi2

Texts=["should schools have uniform","schools discipline","legalize marriage","marriage culture"]
labels=["3","3","7","7"]
vectorizer = CountVectorizer()
term_doc=vectorizer.fit_transform(Texts)
ch2 = SelectKBest(chi2, "all")
X_train = ch2.fit_transform(term_doc, labels)
print ch2.scores_

这给出了结果,但我如何知道哪些特征名称对应于哪些分数?

【问题讨论】:

    标签: python scikit-learn chi-squared


    【解决方案1】:

    它就在文档中:

    get_feature_names()

    【讨论】:

      猜你喜欢
      • 2017-02-10
      • 2017-06-03
      • 2016-05-27
      • 2021-03-26
      • 2014-09-20
      • 2018-06-01
      • 2022-07-06
      • 2012-12-17
      • 2016-08-06
      相关资源
      最近更新 更多