Vektor88
Vektor88

Reputation: 4920

How to interpret k Medoids output

I have found this implementation of K-Medoids and I decided to try it in my code.

My original dataset is a 21x6 matrix.

To generate the distance matrix I'm using:

import scipy.spatial.distance as ssd
distanceMatrix = ssd.squareform(ssd.pdist(matr, 'cosine'))

Then I decide a number of clusters:

clusters = int(np.sqrt(len(matr.data)/2))

And finally:

clusters, medoids = self.cluster(distanceMatrix,clusters)
print(clusters)
print(medoids)

For the given input, I get this output:

[12 12 12 12 12 12 12  7  7  7  7 11 12 12 12 12 12 12 11 12 12]
[12  7 11]

While I was expecting an output similar to sklearn.cluster.KMeans where I have a label for each point in my matrix. How should I treat this kind of output if I want to use the result to scatter cluster elements, like in the picture below (where I used k-Means)? kmeans-example

Upvotes: 2

Views: 1793

Answers (1)

galaxyan
galaxyan

Reputation: 6131

The k-medoids is using datapoints as centers, so print(medoids) would give you the index of centers in your input dataset and print(clusters) would give you which group the data point belong to.
the stars in the graph would be dataset[12],dataset[11], and dataset[7]

Upvotes: 1

Related Questions