Calculating medoid of a cluster (Python)
<p>So I'm running a KNN in order to create clusters. From each cluster, I would like to obtain the medoid of the cluster.</p>

<p>I'm employing a fractional distance metric in order to calculate distances:</p>

<p><a href="https://i.stack.imgur.com/Xtqwi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xtqwi.png" alt="where d is the number of dimensions, the first data point&#39;s coordinates are x^i, the second data point&#39;s coordinates are y^i, and f is an arbitrary number between 0 and 1"></a></p>

<p>where d is the number of dimensions, the first data point's coordinates are x^i, the second data point's coordinates are y^i, and f is an arbitrary number between 0 and 1</p>

<p>I would then calculate the medoid as:</p>

<p><a href="https://i.stack.imgur.com/jayto.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jayto.png" alt="where S is the set of datapoints, and δ is the absolute value of the distance metric used above"></a></p>

<p>where S is the set of datapoints, and δ is the absolute value of the distance metric used above.</p>

<p>I've looked online to no avail trying to find implementations of medoid (even with other distance metrics, but most thing were specifically k-means or k-medoid which [I think] is relatively different from what I want.</p>

<p>Essentially this boils down to me being unable to translate the math into effective programming. Any help would or pointers in the right direction would be much appreciated! Here's a short list of what I have so far:</p>

<ul>
<li>I have figured out how to calculate the fractional distance metric (the first equation) so I think I'm good there.</li>
<li>I know numpy has an argmin() function (documented <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.argmin.html" rel="nofollow noreferrer">here</a>).</li>
<li>Extra points for increased efficiency without lack of accuracy (I'm trying not to brute force by calculating every single fractional distance metric (because the number of point pairs might lead to a factorial complexity...).</li>
</ul>