Ask Your Question

# K means question

Hey everybody,

I'm currently in the process of clustering a set of points into different sections. Though, the k means algorithm requires me to explicitly set the number of clusters to divide the set of points in. Is there an alternative algorithm, where I can pass in a set of points and a maximum distance, which divides point clusters from each other? What I would like to have returned is a list of clusters of yet unknown size, containing a sub-set of points.

I would be very thankful for any directions.

Thanks, Marcel

edit retag close merge delete

## 1 answer

Sort by ยป oldest newest most voted

yes, you can use partition with a distance functor:

struct Dist {
bool operator()(const Point& a, const Point &b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)) < 15;
}
};

vector<Point> input = ...;
vector<int> labels;

partition(input, labels, Dist());

more

## Stats

Asked: 2015-08-14 13:18:51 -0500

Seen: 425 times

Last updated: Aug 14 '15