[英]Get the most important words in the corpus using tf-idf (Gensim)
我正在計算tf-idf如下。
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個單詞。 請讓我知道該怎么做?
假設您的清單確定正確,則應該能夠按照以下方式進行排列:最上方:
from operator import itemgetter
然后在底部:
e=sorted(d, key=itemgetter(1))
top3 = e[:3]
print(top3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.