2017-01-13 73 views
0

我有分類問題。我爲數據建立了一組功能。我用SVM進行分類。我想評估這些功能。打印前10個特徵的名稱及其卡方值

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 

但是當我運行此我得到了以下錯誤

AttributeError: 'SelectKBest' object has no attribute 'scores_'

注:我沒有使用矢量化。我有列表名稱featurenames中的功能名稱,我想打印所有或頂部K功能的名稱和卡方值

回答

1

您只聲明瞭要使用的評分函數以及要選擇的功能數量。但是,功能選擇需要使用數據以使用一些統計測試找到最佳功能,然後才能訪問分數。以下是一個示例,其中X包含功能,Y包含目標值。

ch2= SelectKBest(score_func=chi2, k='all').fit_transform(X, Y) 
print(ch2.scores_) 
相關問題