2017-04-17 39 views
0

參照Map object is not subscriptable error 我用摩西徐的答案來獲取功能名稱。它會產生錯誤「地圖對象不可下載」。代碼如下。我正在使用python 3.x如何獲得選定的功能與他們的分數?

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(train_vectorizer.get_feature_names())[top_ranked_features_indices],ch2.pvalues_[top_ranked_features_indices]): 
    print(feature_pvalue). 

錯誤出現在第二行代碼中。

輸出

('00 8b 4d fc', 3.4028916591534005e-61) 
('51 00 22 05', 3.4028916591534005e-61) 
('00 74 00 61', 8.3973527363656966e-61) 

回答

0

在蟒蛇3.x中,地圖返回迭代器,而不是一個列表。因此,返回的對象不是可以下載的。 您可以將其更改爲list(map(list,zip(*a)))[0]以解決問題。

編輯:

你也可以使用next(map(list,zip(*a)))的分數不加載到內存中,並保持代碼更Python。

+0

非常感謝。有效。 – banu

+0

@banu在同一篇文章中增加一個額外的問題只會造成混亂。看起來好像你得到一個錯誤和一個正確的輸出。請刪除第二個問題。您可以在新帖子中提出新問題,也可以搜索現有解決方案。 – Eran

+0

好的。感謝您的指導。 – banu

相關問題