{"id":7676,"date":"2018-10-18T01:49:36","date_gmt":"2018-10-17T23:49:36","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?post_type=dt_lessons&#038;p=7676"},"modified":"2018-10-20T18:13:40","modified_gmt":"2018-10-20T16:13:40","slug":"k-medoids-in-r-algorithm-and-practical-examples","status":"publish","type":"dt_lessons","link":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/","title":{"rendered":"K-Medoids in R: Algorithm and Practical Examples"},"content":{"rendered":"<div id=\"rdoc\">\n<p>The <strong>k-medoids algorithm<\/strong> is a clustering approach related to k-means clustering for partitioning a data set into k groups or clusters. In k-medoids clustering, each cluster is represented by one of the data point in the cluster. These points are named cluster medoids.<\/p>\n<p>The term medoid refers to an object within a cluster for which average dissimilarity between it and all the other the members of the cluster is minimal. It corresponds to the most centrally located point in the cluster. These objects (one per cluster) can be considered as a representative example of the members of that cluster which may be useful in some situations. Recall that, in k-means clustering, the center of a given cluster is calculated as the mean value of all the data points in the cluster.<\/p>\n<p>K-medoid is a robust alternative to k-means clustering. This means that, the algorithm is less sensitive to noise and outliers, compared to k-means, because it uses medoids as cluster centers instead of means (used in k-means).<\/p>\n<p>The k-medoids algorithm requires the user to specify k, the number of clusters to be generated (like in k-means clustering). A useful approach to determine the optimal number of clusters is the <strong>silhouette<\/strong> method, described in the next sections.<\/p>\n<p>The most common k-medoids clustering methods is the <strong>PAM<\/strong> algorithm (<strong>Partitioning Around Medoids<\/strong>, <span class=\"citation\">(Kaufman and Rousseeuw 1990)<\/span>).<\/p>\n<div class=\"block\">\n<p>In this article, We\u2019ll describe the PAM algorithm and show how to compute PAM in R software.<\/p>\n<p>In the next article, we\u2019ll also discuss a variant of PAM named <em>CLARA<\/em> (Clustering Large Applications) which is used for analyzing large data sets.<\/p>\n<\/div>\n<p>Contents:<\/p>\n<div id=\"TOC\">\n<ul>\n<li><a href=\"#pam-concept\">PAM concept<\/a><\/li>\n<li><a href=\"#pam-algorithm\">PAM algorithm<\/a><\/li>\n<li><a href=\"#computing-pam-in-r\">Computing PAM in R<\/a>\n<ul>\n<li><a href=\"#data\">Data<\/a><\/li>\n<li><a href=\"#required-r-packages-and-functions\">Required R packages and functions<\/a><\/li>\n<li><a href=\"#estimating-the-optimal-number-of-clusters\">Estimating the optimal number of clusters<\/a><\/li>\n<li><a href=\"#computing-pam-clustering\">Computing PAM clustering<\/a><\/li>\n<li><a href=\"#accessing-to-the-results-of-the-pam-function\">Accessing to the results of the pam() function<\/a><\/li>\n<li><a href=\"#visualizing-pam-clusters\">Visualizing PAM clusters<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#summary\">Summary<\/a><\/li>\n<li><a href=\"#references\">References<\/a><\/li>\n<\/ul>\n<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div class='dt-sc-ico-content type1'><div class='custom-icon' ><a href='https:\/\/www.datanovia.com\/en\/product\/practical-guide-to-cluster-analysis-in-r\/' target='_blank'><span class='fa fa-book'><\/span><\/a><\/div><h4><a href='https:\/\/www.datanovia.com\/en\/product\/practical-guide-to-cluster-analysis-in-r\/' target='_blank'> Related Book <\/a><\/h4>Practical Guide to Cluster Analysis in R<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div id=\"pam-concept\" class=\"section level2\">\n<h2>PAM concept<\/h2>\n<p>The use of means implies that k-means clustering is highly sensitive to outliers. This can severely affects the assignment of observations to clusters. A more robust algorithm is provided by the <strong>PAM<\/strong> algorithm.<\/p>\n<\/div>\n<div id=\"pam-algorithm\" class=\"section level2\">\n<h2>PAM algorithm<\/h2>\n<p>The PAM algorithm is based on the search for k representative objects or medoids among the observations of the data set.<\/p>\n<p>After finding a set of k medoids, clusters are constructed by assigning each observation to the nearest medoid.<br \/>\nNext, each selected medoid m and each non-medoid data point are swapped and the objective function is computed. The objective function corresponds to the sum of the dissimilarities of all objects to their nearest medoid.<\/p>\n<p>The SWAP step attempts to improve the quality of the clustering by exchanging selected objects (medoids) and non-selected objects. If the objective function can be reduced by interchanging a selected object with an unselected object, then the swap is carried out. This is continued until the objective function can no longer be decreased. The goal is to find k representative objects which minimize the sum of the dissimilarities of the observations to their closest representative object.<\/p>\n<p>In summary, PAM algorithm proceeds in two phases as follow:<\/p>\n<div class=\"block\">\n<p><strong>Build phase<\/strong>:<\/p>\n<ol style=\"list-style-type: decimal;\">\n<li>Select k objects to become the medoids, or in case these objects were provided use them as the medoids;<\/li>\n<li>Calculate the dissimilarity matrix if it was not provided;<\/li>\n<li>Assign every object to its closest medoid;<\/li>\n<\/ol>\n<p><strong>Swap phase<\/strong>:<br \/>\n4. For each cluster search if any of the object of the cluster decreases the average dissimilarity coefficient; if it does, select the entity that decreases this coefficient the most as the medoid for this cluster; 5. If at least one medoid has changed go to (3), else end the algorithm.<\/p>\n<\/div>\n<p>As mentioned above, the PAM algorithm works with a matrix of dissimilarity, and to compute this matrix the algorithm can use two metrics:<\/p>\n<ol style=\"list-style-type: decimal;\">\n<li>The euclidean distances, that are the root sum-of-squares of differences;<\/li>\n<li>And, the Manhattan distance that are the sum of absolute distances.<\/li>\n<\/ol>\n<div class=\"warning\">\n<p>Note that, in practice, you should get similar results most of the time, using either euclidean or Manhattan distance. If your data contains outliers, Manhattan distance should give more robust results, whereas euclidean would be influenced by unusual values.<\/p>\n<\/div>\n<p>Read more on <a href=\"https:\/\/www.datanovia.com\/en\/lessons\/clustering-distance-measures\/\">distance measures<\/a>.<\/p>\n<\/div>\n<div id=\"computing-pam-in-r\" class=\"section level2\">\n<h2>Computing PAM in R<\/h2>\n<div id=\"data\" class=\"section level3\">\n<h3>Data<\/h3>\n<p>We\u2019ll use the demo data sets \u201cUSArrests\u201d, which we start by scaling (Chapter <a href=\"https:\/\/www.datanovia.com\/en\/lessons\/clustering-distance-measures\/\">data preparation and R packages<\/a>) using the R function <em>scale()<\/em> as follow:<\/p>\n<pre class=\"r\"><code>data(\"USArrests\")      # Load the data set\r\ndf &lt;- scale(USArrests) # Scale the data\r\nhead(df, n = 3)        # View the firt 3 rows of the data<\/code><\/pre>\n<pre><code>##         Murder Assault UrbanPop     Rape\r\n## Alabama 1.2426   0.783   -0.521 -0.00342\r\n## Alaska  0.5079   1.107   -1.212  2.48420\r\n## Arizona 0.0716   1.479    0.999  1.04288<\/code><\/pre>\n<\/div>\n<div id=\"required-r-packages-and-functions\" class=\"section level3\">\n<h3>Required R packages and functions<\/h3>\n<p>The function <em>pam<\/em>() [<em>cluster<\/em> package] and <em>pamk()<\/em> [<em>fpc<\/em> package] can be used to compute <strong>PAM<\/strong>.<\/p>\n<p><span class=\"notice\">The function <em>pamk<\/em>() does not require a user to decide the number of clusters K.<\/span><\/p>\n<p>In the following examples, we\u2019ll describe only the function <em>pam<\/em>(), which simplified format is:<\/p>\n<pre class=\"r\"><code>pam(x, k, metric = \"euclidean\", stand = FALSE)<\/code><\/pre>\n<div class=\"block\">\n<ul>\n<li><strong>x<\/strong>: possible values includes:\n<ul>\n<li>Numeric data matrix or numeric data frame: each row corresponds to an observation, and each column corresponds to a variable.<\/li>\n<li>Dissimilarity matrix: in this case x is typically the output of <strong>daisy()<\/strong> or <strong>dist()<\/strong><\/li>\n<\/ul>\n<\/li>\n<li><strong>k<\/strong>: The number of clusters<\/li>\n<li><strong>metric<\/strong>: the distance metrics to be used. Available options are \u201ceuclidean\u201d and \u201cmanhattan\u201d.<\/li>\n<li><strong>stand<\/strong>: logical value; if true, the variables (columns) in x are standardized before calculating the dissimilarities. Ignored when x is a dissimilarity matrix.<\/li>\n<\/ul>\n<\/div>\n<p>To create a beautiful graph of the clusters generated with the <em>pam<\/em>() function, will use the <em>factoextra<\/em> package.<\/p>\n<ol style=\"list-style-type: decimal;\">\n<li>Installing required packages:<\/li>\n<\/ol>\n<pre class=\"r\"><code>install.packages(c(\"cluster\", \"factoextra\"))<\/code><\/pre>\n<ol style=\"list-style-type: decimal;\" start=\"2\">\n<li>Loading the packages:<\/li>\n<\/ol>\n<pre class=\"r\"><code>library(cluster)\r\nlibrary(factoextra)<\/code><\/pre>\n<\/div>\n<div id=\"estimating-the-optimal-number-of-clusters\" class=\"section level3\">\n<h3>Estimating the optimal number of clusters<\/h3>\n<p>To estimate the optimal number of clusters, we\u2019ll use the average silhouette method. The idea is to compute PAM algorithm using different values of clusters k. Next, the average clusters silhouette is drawn according to the number of clusters. The average silhouette measures the quality of a clustering. A high average silhouette width indicates a good clustering. The optimal number of clusters k is the one that maximize the average silhouette over a range of possible values for k <span class=\"citation\">(Kaufman and Rousseeuw 1990)<\/span>.<\/p>\n<p>The R function <em>fviz_nbclust<\/em>() [<em>factoextra<\/em> package] provides a convenient solution to estimate the optimal number of clusters.<\/p>\n<\/p>\n<div class=\"error\">Here, there are contents\/codes hidden to non-premium members. Signup now to read all of our premium contents and to be awarded a certificate of course completion.<br \/>\n<a href='https:\/\/www.datanovia.com\/en\/pricing\/' target='_self'  class='dt-sc-button   medium  '  style=\"background-color:#FF6600;border-color:#FF6600;color:#ffffff;\">Claim Your Membership Now<\/a>.<\/div>\n<p>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/002-partitional-clustering\/figures\/007-k-medoids-pam-optimal-clusters-wss-1.png\" width=\"518.4\" \/><\/p>\n<div class=\"success\">\n<p>From the plot, the suggested number of clusters is 2. In the next section, we\u2019ll classify the observations into 2 clusters.<\/p>\n<\/div>\n<\/div>\n<div id=\"computing-pam-clustering\" class=\"section level3\">\n<h3>Computing PAM clustering<\/h3>\n<p>The R code below computes PAM algorithm with k = 2:<\/p>\n<pre class=\"r\"><code>pam.res &lt;- pam(df, 2)\r\nprint(pam.res)<\/code><\/pre>\n<pre><code>## Medoids:\r\n##            ID Murder Assault UrbanPop   Rape\r\n## New Mexico 31  0.829   1.371    0.308  1.160\r\n## Nebraska   27 -0.801  -0.825   -0.245 -0.505\r\n## Clustering vector:\r\n##        Alabama         Alaska        Arizona       Arkansas     California \r\n##              1              1              1              2              1 \r\n##       Colorado    Connecticut       Delaware        Florida        Georgia \r\n##              1              2              2              1              1 \r\n##         Hawaii          Idaho       Illinois        Indiana           Iowa \r\n##              2              2              1              2              2 \r\n##         Kansas       Kentucky      Louisiana          Maine       Maryland \r\n##              2              2              1              2              1 \r\n##  Massachusetts       Michigan      Minnesota    Mississippi       Missouri \r\n##              2              1              2              1              1 \r\n##        Montana       Nebraska         Nevada  New Hampshire     New Jersey \r\n##              2              2              1              2              2 \r\n##     New Mexico       New York North Carolina   North Dakota           Ohio \r\n##              1              1              1              2              2 \r\n##       Oklahoma         Oregon   Pennsylvania   Rhode Island South Carolina \r\n##              2              2              2              2              1 \r\n##   South Dakota      Tennessee          Texas           Utah        Vermont \r\n##              2              1              1              2              2 \r\n##       Virginia     Washington  West Virginia      Wisconsin        Wyoming \r\n##              2              2              2              2              2 \r\n## Objective function:\r\n## build  swap \r\n##  1.44  1.37 \r\n## \r\n## Available components:\r\n##  [1] \"medoids\"    \"id.med\"     \"clustering\" \"objective\"  \"isolation\" \r\n##  [6] \"clusinfo\"   \"silinfo\"    \"diss\"       \"call\"       \"data\"<\/code><\/pre>\n<div class=\"success\">\n<p>The printed output shows:<\/p>\n<ul>\n<li>the cluster medoids: a matrix, which rows are the medoids and columns are variables<\/li>\n<li>the clustering vector: A vector of integers (from 1:k) indicating the cluster to which each point is allocated<\/li>\n<\/ul>\n<\/div>\n<p>If you want to add the point classifications to the original data, use this:<\/p>\n<pre class=\"r\"><code>dd &lt;- cbind(USArrests, cluster = pam.res$cluster)\r\nhead(dd, n = 3)<\/code><\/pre>\n<pre><code>##         Murder Assault UrbanPop Rape cluster\r\n## Alabama   13.2     236       58 21.2       1\r\n## Alaska    10.0     263       48 44.5       1\r\n## Arizona    8.1     294       80 31.0       1<\/code><\/pre>\n<\/div>\n<div id=\"accessing-to-the-results-of-the-pam-function\" class=\"section level3\">\n<h3>Accessing to the results of the pam() function<\/h3>\n<p>The function <em>pam<\/em>() returns an object of class <em>pam<\/em> which components include:<\/p>\n<ul>\n<li><strong>medoids<\/strong>: Objects that represent clusters<\/li>\n<li><strong>clustering<\/strong>: a vector containing the cluster number of each object<\/li>\n<\/ul>\n<p>These components can be accessed as follow:<\/p>\n<pre class=\"r\"><code># Cluster medoids: New Mexico, Nebraska\r\npam.res$medoids<\/code><\/pre>\n<pre><code>##            Murder Assault UrbanPop   Rape\r\n## New Mexico  0.829   1.371    0.308  1.160\r\n## Nebraska   -0.801  -0.825   -0.245 -0.505<\/code><\/pre>\n<pre class=\"r\"><code># Cluster numbers\r\nhead(pam.res$clustering)<\/code><\/pre>\n<pre><code>##    Alabama     Alaska    Arizona   Arkansas California   Colorado \r\n##          1          1          1          2          1          1<\/code><\/pre>\n<\/div>\n<div id=\"visualizing-pam-clusters\" class=\"section level3\">\n<h3>Visualizing PAM clusters<\/h3>\n<p>To visualize the partitioning results, we\u2019ll use the function <em>fviz_cluster<\/em>() [<em>factoextra<\/em> package]. It draws a scatter plot of data points colored by cluster numbers. If the data contains more than 2 variables, the <em>Principal Component Analysis (PCA)<\/em> algorithm is used to reduce the dimensionality of the data. In this case, the first two principal dimensions are used to plot the data.<\/p>\n<\/p>\n<div class=\"error\">Here, there are contents\/codes hidden to non-premium members. Signup now to read all of our premium contents and to be awarded a certificate of course completion.<br \/>\n<a href='https:\/\/www.datanovia.com\/en\/pricing\/' target='_self'  class='dt-sc-button   medium  '  style=\"background-color:#FF6600;border-color:#FF6600;color:#ffffff;\">Claim Your Membership Now<\/a>.<\/div>\n<p>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/002-partitional-clustering\/figures\/007-k-medoids-pam-k-medoids-clustering-plot-1.png\" width=\"480\" \/><\/p>\n<\/div>\n<\/div>\n<div id=\"summary\" class=\"section level2\">\n<h2>Summary<\/h2>\n<p>The K-medoids algorithm, PAM, is a robust alternative to k-means for partitioning a data set into clusters of observation.<\/p>\n<p>In k-medoids method, each cluster is represented by a selected object within the cluster. The selected objects are named medoids and corresponds to the most centrally located points within the cluster.<\/p>\n<p>The PAM algorithm requires the user to know the data and to indicate the appropriate number of clusters to be produced. This can be estimated using the function <em>fviz_nbclust<\/em> [in <em>factoextra<\/em> R package].<\/p>\n<p>The R function <em>pam<\/em>() [<em>cluster<\/em> package] can be used to compute PAM algorithm. The simplified format is pam(x, k), where \u201cx\u201d is the data and k is the number of clusters to be generated.<\/p>\n<p>After, performing PAM clustering, the R function <em>fviz_cluster<\/em>() [<strong>factoextra<\/strong> package] can be used to visualize the results. The format is fviz_cluster(pam.res), where pam.res is the PAM results.<\/p>\n<div class=\"warning\">\n<p>Note that, for large data sets, <em>pam<\/em>() may need too much memory or too much computation time. In this case, the function <em>clara<\/em>() is preferable. This should not be a problem for modern computers.<\/p>\n<\/div>\n<\/div>\n<div id=\"references\" class=\"section level2 unnumbered\">\n<h2>References<\/h2>\n<div id=\"refs\" class=\"references\">\n<div id=\"ref-kaufman1990\">\n<p>Kaufman, Leonard, and Peter Rousseeuw. 1990. <em>Finding Groups in Data: An Introduction to Cluster Analysis<\/em>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The k-medoids (or PAM) algorithm is a non-parametric alternative of k-means clustering for partitioning a dataset. This article describes the PAM algorithm and shows how to compute PAM in R software.<\/p>\n","protected":false},"author":1,"featured_media":7962,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-7676","dt_lessons","type-dt_lessons","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>K-Medoids in R: Algorithm and Practical Examples - Datanovia<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"K-Medoids in R: Algorithm and Practical Examples - Datanovia\" \/>\n<meta property=\"og:description\" content=\"The k-medoids (or PAM) algorithm is a non-parametric alternative of k-means clustering for partitioning a dataset. This article describes the PAM algorithm and shows how to compute PAM in R software.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:modified_time\" content=\"2018-10-20T16:13:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/\",\"name\":\"K-Medoids in R: Algorithm and Practical Examples - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg\",\"datePublished\":\"2018-10-17T23:49:36+00:00\",\"dateModified\":\"2018-10-20T16:13:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lessons\",\"item\":\"https:\/\/www.datanovia.com\/en\/lessons\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"K-Medoids in R: Algorithm and Practical Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"name\":\"Datanovia\",\"description\":\"Data Mining and Statistics for Decision Support\",\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.datanovia.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\",\"name\":\"Datanovia\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"width\":98,\"height\":99,\"caption\":\"Datanovia\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"K-Medoids in R: Algorithm and Practical Examples - Datanovia","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/","og_locale":"en_US","og_type":"article","og_title":"K-Medoids in R: Algorithm and Practical Examples - Datanovia","og_description":"The k-medoids (or PAM) algorithm is a non-parametric alternative of k-means clustering for partitioning a dataset. This article describes the PAM algorithm and shows how to compute PAM in R software.","og_url":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/","og_site_name":"Datanovia","article_modified_time":"2018-10-20T16:13:40+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/","url":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/","name":"K-Medoids in R: Algorithm and Practical Examples - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg","datePublished":"2018-10-17T23:49:36+00:00","dateModified":"2018-10-20T16:13:40+00:00","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/C12.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/lessons\/k-medoids-in-r-algorithm-and-practical-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"Lessons","item":"https:\/\/www.datanovia.com\/en\/lessons\/"},{"@type":"ListItem","position":3,"name":"K-Medoids in R: Algorithm and Practical Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.datanovia.com\/en\/#website","url":"https:\/\/www.datanovia.com\/en\/","name":"Datanovia","description":"Data Mining and Statistics for Decision Support","publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanovia.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanovia.com\/en\/#organization","name":"Datanovia","url":"https:\/\/www.datanovia.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","width":98,"height":99,"caption":"Datanovia"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/"}}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/7676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/dt_lessons"}],"author":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/comments?post=7676"}],"version-history":[{"count":1,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/7676\/revisions"}],"predecessor-version":[{"id":7677,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/7676\/revisions\/7677"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/7962"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=7676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}