I asked the same question at Cross Validated, here

I implemented a K-Medoid clustering algorithm recently; I have a number of points $x_1, ..., x_n$ which have various properties and a distance function $d$ that maps two points to some nonnegative number. The clustering works fine (with some number $k$ of cluster medoids where $k$ is a lot smaller than $n$), but I wanted to be able to change the clustering according to a property of my points, more specifically I'd like more clusters to appear where my points have a high value in some property. I tried scaling the distance matrix like this:

$newd (x_i, x_j) = p(x_i) * d(x_i, x_j)$
where $p(x)$ is the value of the property of $x$.

My expected result was to see more clusters around points with a high value of $p$, but instead, I get the exact same clusters. I'm probably missing something very basic here.

So, to sum up, my question: I'd like to see more clusters around points with a certain property. I assume I can achieve this by changing my distance function, but I don't quite understand how to do it?

  • 1
    $\begingroup$ If you want a cluster around x_i to be more likely, you need make the scaling factor smaller. So what about $d' = \frac{1}{p} d$ ? $\endgroup$ Oct 9, 2020 at 22:14

1 Answer 1


That technique is commonly called weighted or observation-weighted k-means. The weighting changes how the cluster centers (medoids in your case) are calculated.

If you are using R, the WeightedCluster package has weighted K-Medoids implemented.

  • $\begingroup$ In Python, sci-kit-learn and kmedoids don't mention weights. Do you know if Python has an implementation of weighted k-medoids? $\endgroup$
    – emonigma
    Apr 12 at 18:15

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.