I have a dataset consisting of addresses (points) that have several attributes; one that distinguishes the "sort" of address and one attribute that contains a numerical value.

I want to cluster these points based on:

  1. their distance from each other
  2. the sort of address

However, the summed numerical attribute per cluster cannot exceed a certain threshold value.

In other words, the system needs to form clusters but needs to stop clustering as soon as the sum of the numerical value attached to each address has been reached.

How do I even go about it? I have R, Python, and another geo- applications at my disposal.

It seems that none of the existing clustering algorithms work. For k- means, for example, I need to know the number of clusters beforehand, which I don't.

It seems rather simple, but I can't find a basic methodology to follow.

  • $\begingroup$ Your proposed procedure needs some clarification. What do you mean by "stop clustering"? Some algorithms iteratively cluster and re-cluster the entire dataset, whereas other algorithms build clusters in batches, or one data point at a time. You will need to clarify this before the question can be answered. $\endgroup$ Oct 4, 2018 at 13:01
  • $\begingroup$ I think I mean one data point at a time. I think I need an algorythm that starts with placing each point in a seperate cluster, and then continues to merge clusters untill that numerical threshold value is reached. Note, I said that's what I THINK needs to happen. Maybe there are other algorythms that do work iteratively but give me the same result. $\endgroup$
    – Minka
    Oct 4, 2018 at 13:42
  • $\begingroup$ With of course taking into account the distance (the points need to be close to each other), and they also need to belong to the same category(type) $\endgroup$
    – Minka
    Oct 4, 2018 at 13:43
  • $\begingroup$ Is it only important to add the closest points to a cluster while a cluster still has capacity, or is it also important to capture your numerical value efficiently (so that your cluster preferentially chooses the highest value points as in a knapsack problem)? $\endgroup$ Sep 5, 2020 at 6:48
  • $\begingroup$ Also, must all your points belong to a cluster? $\endgroup$ Sep 5, 2020 at 6:49

1 Answer 1


Based on your comments, you are looking for agglomerative hierarchical clustering.

You start with one point as its own cluster. Then iterate over pairs of clusters, merging them according to some criterion.

Typically you need to select a "cut point" after which you stop combining clusters. This is not an easy problem in general, and for the most part involves eyeballing your data until it "looks right", much like choosing K in K-means. In your case, however, you can use the external criterion you have in mind. You will need to recompute its value at every step, and then simply stop when its value passes the desired threshold.

  • $\begingroup$ Thank you. Yes, that what I thought too... I'll check for packages that offer that in R. Are you familiar with FME , and if so, do you know how to do this type of clustering in FME? As far as I can tell, FME only offers k-means clustering, but maybe I'm mistaken? $\endgroup$
    – Minka
    Oct 4, 2018 at 13:55
  • $\begingroup$ @Minka I've never used FME, sorry. $\endgroup$ Oct 4, 2018 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.