Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Printing k-means clustered clusters
I'm trying to print the number of the cluster and the words inside the cluster.
Out put should be:
Cluster 1: dog run walk
Cluster 2: three four

Here's the making of he clusters:
def kmeans_clustering(words):
    n_clusters = 3
    clusterer = KMeansClusterer(n_clusters, euclidean_distance, repeats=10)
    vectors = [numpy.array(normalize(context_vector[word])) for word in words]
    assigned_clusters = clusterer.cluster(vectors, assign_clusters=True, trace=True)

kmeans_clustering('three four dog run walk'.split())
I tried to iterate through the word and then append the the cluster number and the word to a list,
but I get a out of range error and I intuitively also think it might not work.

This is the only thing I have gotten to work, but it's not what I want.
    for i, word in enumerate(words):
        print ('Cluster', str(assign_clusters[i], word))
Larz60+ wrote Apr-06-2020, 12:33 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Please use proper code tags while posting a thread
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Does your problem have anything to do with K Means Clustering, or is it just processing your results? Please provide more detail and show what you have tried and the error message you are getting.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Comparing means in dataFrames Holly 0 789 Jun-23-2018, 01:52 PM
Last Post: Holly
  K means clustering using heatmap Rifscape 0 1,643 Sep-10-2017, 11:08 PM
Last Post: Rifscape

Forum Jump:

Users browsing this thread: 1 Guest(s)