【问题标题】:Topic Similarity in one model to csv Matrix一个模型与 csv 矩阵的主题相似性
【发布时间】:2018-05-31 14:45:48
【问题描述】:

我想生成一个主题到主题矩阵,以便使用来自 gensim LDA 的函数 gensim.models.ldamodel.diff 找到类似的主题来生成内部集群。 如何将生成的数据保存到 csv 中,其中包含主题上的主题和单元格中的距离(在本例中为 hellinger 距离)? 这段代码对我不起作用:

from gensim import models
import pandas

dateiname_model1 = "lda.model"
model1 =  models.LdaModel.load(dateiname_model1)

topic_over_topic = model1.diff(model1, annotation=True)

topic_over_topic_speicherpfad = "topic_over_topic_similarity.csv"
pandas.DataFrame(topic_over_topic).to_csv(topic_over_topic_speicherpfad, sep=';')

【问题讨论】:

  • 会不会是因为gensim.models.ldamodel.diff 返回了一个矩阵元组,而不仅仅是主题-主题矩阵?
  • 这也许是可能的。但是这个问题的答案是什么?我真的不知道该如何处理
  • 解包元组的工作方式如下:a, b = some_tuple。请参阅文档的this section。在你的情况下尝试topic_over_topic, annotation = model1.diff(model1, annotation=True)。如果这不起作用,更详细的问题描述可能会有所帮助。

标签: python-3.x export-to-csv gensim


【解决方案1】:

它适用于代码topic_over_topic, annotation = model1.diff(model1, annotation=True):

from gensim import models
import pandas

dateiname_model1 = "lda.model"
model1 =  models.LdaModel.load(dateiname_model1)

topic_over_topic, annotation = model1.diff(model1, annotation=True)

topic_over_topic_speicherpfad = "topic_over_topic_similarity.csv"
pandas.DataFrame(topic_over_topic).to_csv(topic_over_topic_speicherpfad, sep=';')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 2016-04-23
    • 2019-11-15
    • 1970-01-01
    • 2018-10-28
    相关资源
    最近更新 更多