【发布时间】:2016-03-13 22:02:51
【问题描述】:
我正在使用包WordCloud 来显示由scikit LDA 生成的单词(潜在狄利克雷分配)。对于 LDA 生成的每个主题,我都会有一个图表。我希望能够在网格中绘制所有图表以允许并排可视化。 本质上,我有一个函数,它将 LDA 模型作为输入,以及我想要可视化的 LDA 主题,然后绘制一个 wordcloud:
from wordcloud import WordCloud
import matplotlib.pyplot as plt
SEED=0
def topicWordCloud(model, topicNumber, WCmaxWords,WCwidth, WCheight):
topic = model.components_[topicNumber]
tupleList = [(tf_feature_names[i],int(topic[i]/topic.sum()*10000)) for i in range(len(topic))]
wordcloud = WordCloud(width=WCwidth, height=WCheight, max_words=WCmaxWords, random_state=42).generate_from_frequencies(tupleList)
plt.figure( figsize=(20,10) )
plt.imshow(wordcloud)
plt.axis("off")
topicWordCloud(model=lda, topicNumber=2, WCmaxWords=100,WCwidth=800, WCheight=600)
如何循环浏览我的所有主题 (n_topics) 以可视化网格中的所有图表?我的想法是这样的:
fig = plt.figure()
for i in range(n_topics):
plt.subplot(2,1,i+1)
#something here
【问题讨论】:
标签: python matplotlib lda word-cloud