2017-11-17 16 views
1

次のようにtf-idfを計算しています。tf-idf(Gensim)を使用してコーパス内で最も重要な単語を取得する

texts=['human interface computer', 
'survey user computer system response time', 
'eps user interface system', 
'system human system eps', 
'user response time'] 

dictionary = corpora.Dictionary(texts) 
corpus = [dictionary.doc2bow(text) for text in texts] 
tfidf = models.TfidfModel(corpus) 
corpus_tfidf = tfidf[corpus] 
analyzedDocument = namedtuple('AnalyzedDocument', 'word tfidf_score') 
d=[] 
for doc in corpus_tfidf: 
    for id, value in doc: 
     word = dictionary.get(id) 
     score = value 
     d.append(analyzedDocument(word, score)) 

はしかし、今、私は最高のidf値を持っている単語を使用して、私のコーパスの中で最も重要な3の単語を識別します。私にそれをする方法を教えてください?次のように

答えて

0

あなたがリストさd [OK]を取得していると仮定すると、あなたはそれが配置され得ることができる必要があります:

e=sorted(d, key=itemgetter(1)) 
top3 = e[:3] 
print(top3) 

その後
from operator import itemgetter 

下部にある:上部に

関連する問題