Python Forum
How to visualize cluster centres using word cloud in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to visualize cluster centres using word cloud in python?
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting a valueError. And not sure why? My goal is to visualize the correlation ReadytoCode 0 467 Dec-11-2023, 05:33 AM
Last Post: ReadytoCode
  Deploy Python to Cloud and save output to Google Drive chandrabr80 2 1,559 Jan-25-2022, 06:56 AM
Last Post: ndc85430
  Python Networkx: Visualize an edge weight with a bubble/circle uvw 0 1,990 Sep-01-2021, 06:26 AM
Last Post: uvw
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,488 Aug-12-2021, 04:25 PM
Last Post: palladium
  Python Speech recognition, word by word AceScottie 6 15,984 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  Visualize Geo Map/Calculate distance zarize 1 1,890 Dec-05-2019, 08:36 PM
Last Post: Larz60+
  print a word after specific word search evilcode1 8 4,815 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  Plot multiple csv into one graph problem with visualize linkxxx86 1 5,711 Oct-14-2019, 05:54 PM
Last Post: linkxxx86
  Can't visualize maps using Gmaps mPlummers 0 3,545 Sep-11-2019, 02:38 PM
Last Post: mPlummers
  Upload files to Google/Azure/AWS or cloud drives using python tej7gandhi 0 1,910 May-11-2019, 03:02 PM
Last Post: tej7gandhi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020