擅长:python、mysql、java
<p>以下对我有效:
首先,创建一个lda模型并定义集群/主题,如<a href="https://stackoverflow.com/questions/20984841/topic-distribution-how-do-we-see-which-document-belong-to-which-topic-after-doi/" title="Text Clustering">Topic Clustering</a>中所述-确保最小概率为0。
接下来,使用<code>lda_corpus = lda[corpus]</code>确定LDA语料库
现在将属于每个主题的数据中的文档标识为一个列表,下面的示例有两个主题。df是我的原始数据,它有一个列文本</p>
<pre><code>cluster1 = [j for i,j in zip(lda_corpus,df.texts) if i[0][1] > .2]
cluster2 = [j for i,j in zip(lda_corpus,df.texts) if i[1][1] > .2]
</code></pre>
<p>获取每个集群的单词Cloud。你可以包括尽可能多的停止语。确保清除集群中的数据,如删除停止字、词干等。我跳过这些步骤,以便每个集群都清除了文本/文档。</p>
<pre><code>wordcloud = WordCloud(relative_scaling = 1.0, stopwords=("xxx", 'yyy').generate(' '. join(cluster1))
</code></pre>
<p>最后使用matplotlib绘制word cloud</p>
<pre><code>plt.imshow(wordcloud)
</code></pre>