繁体   English   中英

主题建模,创建经过训练的 LDA 的子图

[英]Topic modeling, creating a subplot of trained LDA

请使用词云可视化我的前 25 个主题模型。 我希望子图并排放置。 我已经训练了 model。 topics包含训练的 LDA model。

下面是我的代码:

from gensim.test.utils import common_texts
from gensim.corpora.dictionary import Dictionary
import gensim
import matplotlib.pyplot as plt
from wordcloud import WordCloud

lda_model = gensim.models.ldamodel.LdaModel(corpus=corpus,
                                           id2word=dictionary,
                                           num_topics=25, #Identifies the 25 topic trends for transportation
                                           random_state=100,
                                           update_every=1,
                                           chunksize=100,
                                           passes=10,
                                           alpha='auto',
                                           per_word_topics=True)


def dsplay_wordcloud(H, W):
  fig, axes = plt.subplots(5, 5, figsize=(30, 15), sharex=True)
  axes = axes.flatten()
  cloud = WordCloud(stopwords=stop_words,
                  background_color='white',
                  # width=2500,
                  # height=1800,
                  # max_words=200,
                  # max_font_size=30
                  prefer_horizontal=0.5
                  )
  for topic_idx, t in enumerate(H):
    ax = axes[topic_idx]
    for t in range(W):
      plt.imshow(cloud.fit_words(dict(lda_model.show_topic(t, 200))))
      plt.axis("off")
      plt.title("Topic Number " + str(t), fontdict = {'fontsize' : 20})
      fig.suptitle('Topic display', fontsize=14, fontweight='bold')

  plt.subplots_adjust(top=0.90, bottom=0.05, wspace=0.90, hspace=0.3)
  plt.show()


dsplay_wordcloud(lda_model, lda_model.num_topics)

我需要此代码的帮助。 下面是错误代码

Output 和错误代码图片。

cloud()更改为cloud 错误是 Python 说,“你试图称cloud为 function,但它不是 function,它是WordCloud object。”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM