2016-12-23 5 views
0

こんにちは、私は次のリストを持っている:次のtfidfモデルで最も代表的な機能を得るにはどうすればいいですか?

listComments = ["comment1","comment2","comment3",...,"commentN"] 

私は次のように私のコメントからモデルを取得するためにTFIDFのベクトライザーを作成:

tfidf_vectorizer = TfidfVectorizer(min_df=10,ngram_range=(1,3),analyzer='word') 
tfidf = tfidf_vectorizer.fit_transform(listComments) 

私が望む私のモデルの詳細をundestandするために、

print("these are the features :",tfidf_vectorizer.get_feature_names()) 
print("the vocabulary :",tfidf_vectorizer.vocabulary_) 

を、これは私が私のモデルはインクルードはVEのために使用されていることを考える単語のリストを与えている:最も代表的な機能を得るために、私が試しましたctorization:

these are the features : ['10', '10 days', 'red', 'car',...] 

the vocabulary : {'edge': 86, 'local': 96, 'machine': 2,...} 

私は30の、最も代表的な特徴を取得する方法を見つけるしたいと思いますしかし、私は私のTFIDFモデルで最高値を達成した単語、最高の逆frecuencyで、私が読んでいた言葉の意味私はこの方法を見つけることができませんでした。この問題の助けを借りて本当に感謝しています。

答えて

1

idfのスコアに関する語彙のリストを入手したい場合は、idf_属性とargsortそれ。

# create an array of feature names 
feature_names = np.array(tfidf_vectorizer.get_feature_names()) 

# get order 
idf_order = tfidf_vectorizer.idf_.argsort()[::-1] 

# produce sorted idf word 
feature_names[idf_order] 

各ドキュメントのtfidfスコアのソートされたリストを取得したい場合は、同様のことを行います。

# get order for all documents based on tfidf scores 
tfidf_order = tfidf.toarray().argsort()[::-1] 

# produce words 
feature_names[tfidf_order] 
+0

私は本当にありがとう、 – neo33