k-means - get the sizes of clusters and every element in a cluster #3663
Replies: 5 comments
|
|
As far as I'm concerned, it just shows the histogram of each element in the whole 180K vector's appearing count, but not actually the sizes of clusters and every element in a cluster |
|
Oops, btw you can use the tools mentioned here: https://github.com/facebookresearch/faiss/wiki/Faiss-building-blocks:-clustering,-PCA,-quantization#assignment |
|
I'm not sure @Lorisyy's link has the answer to @varvaralitvinova's question, but for getting counts, we can do: from collections import Counter
counter = Counter()
for c in I.reshape(-1):
counter[c] += 1
sorted(counter.items())Returns: However, it'd really be nice to have a built-in method to extract the elements of each cluster easily. |
|
I try to use two methods to get the amount of each cluster. My data is 100M * 1536D and 10 class def cluster_num(I:np.ndarray,ncentroids:int)->None:
clNum={i:0 for i in range(ncentroids)}
for i in I.reshape(1,-1)[0]:
clNum[i]+=1
print(f"The num of each cluster:\n{clNum}")Thist way will comsume 0.7367s. 2️⃣ use |
Uh oh!
There was an error while loading. Please reload this page.
I have used k-means clustering on 180K vectors, I have 20 clusters and I would like to see how many elements each cluster contains. How can I do that?
All reactions