R Data Analysis Cookbook, Second Edition - Second Edition
by Kuntal Ganguly, Davor Lozić, Mzabalazo Z. Ngwenya, Andrew Bauman, Shanthi Viswanathan, Viswa Viswanathan
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access