banditpam is an R package that lets you do \(k\)-mediods clustering efficiently as
described in Tiwari, et. al. (2020).
We illustrate with a simple example using simulated data from a Gaussian Mixture Model with the the following means: \((0, 0)\), \((-5, 5)\) and \((5, 5)\).
Let’s cluster the observations in this
X matrix using 3
clusters. The first step is to create a
Next we fit the data with a specified loss, \(l_2\) here. A good habit is to set the seed before fitting for reproducibility.
And we can now extract the medoid observation indices.
A plot shows the results where we color the medoids in red.
We can also change the loss function and see how the mediods change.
One can query some performance statistics too; see help on