我有一个分类问题。我为数据构建了一组功能。我使用 SVM 对 .我想评估功能。
ch2=SelectKBest(score_func=chi2, k='all')
top_ranked_features = sorted(enumerate(ch2.scores_),key=lambda x:x[1], reverse=True)[:1000]
top_ranked_features_indices = map(list,zip(*top_ranked_features))[0]
for feature_pvalue in zip(np.asarray(featurenames)[top_ranked_features_indices],ch2.pvalues_[top_ranked_features_indices]):
print feature_pvalue
但是当我运行这个时,我收到以下错误
属性错误:"选择KBest"对象没有属性"scores_"
注意:我没有使用矢量化器。我在列表名称featurenames
中有特征的名称,我想打印所有或前 K 个特征的名称和卡方值
您只声明了要使用的评分函数以及要选择的功能数量。但是,特征选择需要数据来使用一些统计测试找到最佳特征,然后您就可以访问分数。下面是一个示例,其中X
包含要素,Y
包含目标值。
ch2= SelectKBest(score_func=chi2, k='all').fit_transform(X, Y)
print(ch2.scores_)