选择功能后显示功能名称 [英] show feature names after feature selection

查看:66
本文介绍了选择功能后显示功能名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为文本构建一个分类器,现在我使用TfidfVectorizer和SelectKBest选择功能,如下所示:

I need to build a classifier for text, and now I'm using TfidfVectorizer and SelectKBest to selection the features, as following:

vectorizer = TfidfVectorizer(sublinear_tf = True, max_df = 0.5, stop_words = 'english',charset_error='strict')

X_train_features = vectorizer.fit_transform(data_train.data)
y_train_labels = data_train.target;

ch2 = SelectKBest(chi2, k = 1000)
X_train_features = ch2.fit_transform(X_train_features, y_train_labels)

我要在选择k个最佳功能后打印出所选功能的名称(文本),有什么办法吗?我只需要打印出选定的功能名称,也许我应该改用CountVectorizer?

I want to print out selected features name(text) after select k best features, is there any way to do that? I just need to print out selected feature names, maybe I should use CountVectorizer instead?

推荐答案

以下方法应该起作用:

np.asarray(vectorizer.get_feature_names())[ch2.get_support()]

这篇关于选择功能后显示功能名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆