O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The PAM algorithm is based on the search for k-medoids among the observations of the dataset. Unlike K-means clustering, where the calculation of cluster centroids could result in the centroid being outside the actual data points, medoids should always be represented from within the actual data points. After finding a set of k-medoids, k-clusters are constructed by assigning each observation to the nearest medoid. 

In this example, we first apply the PAM algorithm using the pam() function from the cluster package on the scaled protein intake data frame. Next, we find the four cluster medoids (Romania, W Germany, Sweden, and Spain) from the fitted PAM model and finally visualize the cluster plot using fviz_cluster() from the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required