# How to find the best clustering method?

I have a data set where the samples are people and the feature are their age, sex, location, job, height, weight… Then I will have a new person with the same information and my goal is the find the twenty closest persons from him/her.

I think a clustering algorithm on Python could do the job. But there is a lot of different clustering algorithms and I don’t know which one will fit my problem the best.

KMeans seems to be the easiest clustering method but I don’t know the number of clusters. Same problem with Ward hierarchical clustering.

Mean shift seems more advanced and complicated, I haven’t found a lot of documentation on it. Then my data set is about $100 000$ samples and the maximum recommended is $10 000$ for MeanShift but I could easily separate the data set per area to reduce its size.

Do you think a clustering method is a good idea ? Which one should be the best for my problem ?

• there are heuristics that can be used to determine the best level of the hierarchy in hierarchical clustering (see section 3.2 of factominer.free.fr/docs/HCPC_husson_josse.pdf). I recommend the FactoMineR R package. Jul 9, 2016 at 9:19
• You describe a similarity search, not clustering. Jul 10, 2016 at 1:30

## 1 Answer

If you're looking for the 20 most similar persons I would recommend a simple k-NN classifier with k = 1. That means all instances of a person are represented by only one (perhaps big) feature vector. After all distances are calculated regarding all feature vectors (= persons) you just sort them in an ascending order and pick the 20 nearest neighbours. That's it...

• That's a good idea. Do you recommend a particular library to do this ? Jul 9, 2016 at 10:05
• You don't need a library for a simple k-NN classifier. You can implement it in less than 8 lines of code. The core of a k-NN is distance function. I recommend to use something simple like a Manhatten distance function: $/sum_{i=0}^n |x_{i} - y_{i}|$ Jul 9, 2016 at 10:39
• This is a good idea but I don't think it's quite as simple here, because the data includes continuous and categorical data. I think that some effort will need to be put into defining the distance function. Jul 9, 2016 at 13:53
• I see....well try out one of the surveys here: bfy.tw/6fKN Jul 9, 2016 at 14:11