主题相似性在一个模型中与csv矩阵

时间:2018-05-31 14:45:48

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

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

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=';')

1 个答案:

答案 0 :(得分:0)

它适用于代码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=';')