# What's the best way to detect crowds?

I have a dictionary containing people and the distance between each pair in the following format:

{
"ID_person1": {"ID_person2": 100, "ID_person3": 50},
"ID_person2": {"ID_person1": 100, "ID_person3": 40},
"ID_person3": {"ID_person1": 50, "ID_person2": 40},
}


Since I have all distances between pairs, I'm using K-means to divide them into k clusters (groups), given k, where all elements in a group are as close as possible to the other elements in the same group.

Since K-means is iterative, is there any ohter way to detect crowds with better performance.

• can you share a sample (reproducible) of the structure of your data? – Julio Jesus Jan 4 at 23:40
• without more context, I would go with a density-based algorithm such as DBSCAN, since I assume you do not have a prior knowledge of the number of clusters – Julio Jesus Jan 4 at 23:42
• I also assume you should create an X matrix with features for each personid for example mean distance of its k closest neighbours, closest id, remotest id, etc and whit that matrix you can now apply a cluster algorithm – Julio Jesus Jan 4 at 23:46
• Let me edit the structure of my data. The number of clusters should be relation between the number of people and the number of elements in a group. I think it's not part of the algorithm discussed here because it's quite easy. – Maf Jan 5 at 0:14