Python Forum
How to visualize cluster centres using word cloud in python? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to visualize cluster centres using word cloud in python? (/thread-12282.html)



How to visualize cluster centres using word cloud in python? - shanky - Aug-17-2018

I have performed kmeans clustering on a dataset with term frequencies. I have created 5 clusters. Now I want to combine the true labels of the frequencies to the actual terms in another document called "terms".

Basically I want to combine the frequencies to terms and then make 5 wordclouds for the 5 clusters.

I have some code written, but not able to do that successfully.

The code I have is:

arr = []
j = 0
v = np.where(np.asarray(assigned_clusters) == 0)

words = terms #list(model.vocab)
for i, word in enumerate(words):
print(word + ":" + str(v[i]))

arr.append(word)
abc = str(arr)

wordcloud = WordCloud(stopwords=STOPWORDS,background_color='white', width=1200, height=1000).generate_from_text(abc)
print(wordcloud.words_)
fig = plt.figure()
plt.imshow(wordcloud)
plt.show()
I am getting syntax errors from arr.append() and onwards

Not sure what the problem is. Any help would be appreciated. Thanks