2017-11-17 1 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의 확인을 받고 가정하면, 당신은 배열 얻을 수 있어야합니다 :

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

다음
from operator import itemgetter 

하단의 : 상단

관련 문제