【问题标题】:Get the most important words in the corpus using tf-idf (Gensim)使用 tf-idf (Gensim) 获取语料库中最重要的单词
【发布时间】:2017-11-18 08:35:33
【问题描述】:

我正在计算 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 个词。请告诉我该怎么做?

【问题讨论】:

    标签: python gensim tf-idf


    【解决方案1】:

    假设您的列表没有问题,您应该能够将其排列如下:在顶部:

    from operator import itemgetter
    

    然后在底部:

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

    【讨论】:

      猜你喜欢
      • 2014-09-01
      • 2016-08-07
      • 2020-01-06
      • 2020-03-16
      • 2017-12-27
      • 2021-02-24
      • 2014-04-21
      • 2018-03-23
      • 2013-05-31
      相关资源
      最近更新 更多