R Data Analysis Cookbook by Viswanathan Viswa & Viswanathan Shanthi
Author:Viswanathan, Viswa & Viswanathan, Shanthi
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2015-05-28T16:00:00+00:00
How it works...
In step 1 the data is read and in step 2 we define the convenience function for scaling a set of variables in a data frame.
In step 3 the convenience function is used to scale only the variables of interest. We leave out the No, model_year, and car_name variables.
In step 4 the distance matrix is created based on the standardized values of the relevant variables. We have computed Euclidean distances; other possibilities are: maximum, manhattan, canberra, binary, and minkowski.
In step 5 the distance matrix is passed to the hclust function to create the clustering model. We specified method = "ward" to use Ward's method, which tries to get compact spherical clusters. The hclust function also supports single, complete, average, mcquitty, median, and centroid.
In step 6 the resulting dendrogram is plotted. We specified labels=FALSE because we have too many cases and printing them will only add clutter. With a smaller dataset, using labels = TRUE will make sense. The hang argument controls the distance from the bottom of the dendrogram to the labels. Since we are not using labels, we specified hang = 0 to prevent numerous vertical lines below the dendrogram.
The dendrogram shows all the cases at the bottom (too numerous to distinguish in our plot) and shows the step-by-step agglomeration of the clusters. The dendrogram is organized in such a way that we can obtain a desired set of clusters, say K, by drawing a horizontal line in such a way that it cuts across exactly K vertical lines on the dendrogram.
Step 7 show how to use the rect.hclust function to demarcate the cases comprising the various clusters for a selected value of k.
Step 8 shows how we can use the cutree function to identify, for a specific K, which cluster each case of our data belongs to.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(22432)
Hello! Python by Anthony Briggs(21622)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(20183)
Dependency Injection in .NET by Mark Seemann(19563)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(19311)
Kotlin in Action by Dmitry Jemerov(19233)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(18774)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(17576)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(16965)
Grails in Action by Glen Smith Peter Ledbrook(16726)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(14219)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(12199)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(10923)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10597)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(10029)
Hit Refresh by Satya Nadella(9115)
The Kubernetes Operator Framework Book by Michael Dame(8537)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8362)
Robo-Advisor with Python by Aki Ranin(8305)