The *k*-medoids algorithm is a clustering algorithm related to the *k*-means algorithm and the medoidshift algorithm. Both the *k*-means and *k*-medoids algorithms are partitional (breaking the dataset up into groups) and both attempt to minimize the distance between points labeled to be in a cluster and a point designated as the center of that cluster.

In contrast to the *k*-means algorithm, *k*-medoids chooses datapoints as centers (medoids or exemplars) and works with an arbitrary matrix of distances between datapoints instead of L_{2} norm. This method was proposed in 1987 for the work with L_{1} norm and other distances.

*k*-medoid is a classical partitioning technique of clustering that clusters the data set of *n* objects into *k* clusters known a priori. A useful tool for determining *k* is the silhouette.

It is more robust to noise and outliers as compared to *k*-means because it minimizes a sum of pairwise dissimilarities instead of a sum of squared Euclidean distances.

A medoid can be defined as the object of a cluster, whose average dissimilarity to all the objects in the cluster is minimal i.e. it is a most centrally located point in the cluster.

The most common realisation of *k*-medoid clustering is the **Partitioning Around Medoids (PAM)** algorithm and is as follows:

1) Initialize: randomly select *k* of the *n* data points as the medoids

2) Associate each data point to the closest medoid. ("closest" here is defined using any valid distance metric, most commonly Euclidean distance, Manhattan distance or Minkowski distance)

3) For each medoid *m*

For each non-medoid data point *o*

Swap *m* and *o* and compute the total cost of the configuration

4) Select the configuration with the lowest cost.

5) Repeat steps 2 to 4 until there is no change in the medoid.