{"id":4048,"date":"2017-03-21T16:32:42","date_gmt":"2017-03-21T21:32:42","guid":{"rendered":"http:\/\/hoolihan.net\/blog-tim\/?p=4048"},"modified":"2017-03-21T16:51:05","modified_gmt":"2017-03-21T21:51:05","slug":"clustering-in-r","status":"publish","type":"post","link":"http:\/\/hoolihan.net\/blog-tim\/2017\/03\/21\/clustering-in-r\/","title":{"rendered":"Clustering in R"},"content":{"rendered":"<p>Clustering is a useful technique for exploring your data. It groups records into clusters based on similar features. It&#8217;s also a key technique of unsupervised learning. The following is a simple example in R where I plotted the clusters and centroids. <\/p>\n<p><a href=\"http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/CarClusters.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/CarClusters.png\" alt=\"kmeans() car clusters with centroids\" width=\"1000\" height=\"626\" class=\"alignnone size-full wp-image-4049\" srcset=\"http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/CarClusters.png 1000w, http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/CarClusters-300x188.png 300w, http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/CarClusters-768x481.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>The example uses the mtcars dataset built into R, which contains auto data extracted from Motor Trend Magazine in 1973-1974.<\/p>\n<p>Clustering is done with the kmeans() function. Note that the graph is 2-dimensional, and I cluster by 2 features, but you could cluster by more features and project down to a 2-dimensional plane. <\/p>\n<p>Feel free to make suggestions:<\/p>\n<script src=\"https:\/\/gist.github.com\/33318c473a6db06531d6357c51371741.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>Clustering is a useful technique for exploring your data. It groups records into clusters based on similar features. It&#8217;s also a key technique of unsupervised learning. The following is a simple example in R where I plotted the clusters and centroids. The example uses the mtcars dataset built into R, which contains auto data extracted [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,306,267],"tags":[312,313,314,315],"class_list":["post-4048","post","type-post","status-publish","format-standard","hentry","category-data","category-data-science","category-r","tag-clustering","tag-ggplot2","tag-kmeans","tag-unsupervised-learning"],"_links":{"self":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/4048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/comments?post=4048"}],"version-history":[{"count":0,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/4048\/revisions"}],"wp:attachment":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/media?parent=4048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/categories?post=4048"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/tags?post=4048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}