{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Copy of Assignment 10.txt

Copy of Assignment 10.txt - #Assignment#10 Unsupervised...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#Assignment #10: Unsupervised Learning #Problem 1 #Consider the USArrests data which is part of the base R package (no need to install new package). #Perform hierarchical clustering on the states. #install.packages("reshape2") library(reshape2) library(ISLR) attach(USArrests) #(a) Using hierarchical clustering with complete linkage and Euclidean distance, cluster the states. usar.hc.comp <- hclust(dist(USArrests), method = "complete") plot(usar.hc.comp, main = "Hierarchical Clustering - Complete Linkages", xlab = "", sub = "", cex = 0.9) #(b) Cut the dendrogram at a height that results in three distinct clusters. Which states belong to #which clusters? #Cut dendrogram to three distinct clusters usar.cut = data.frame(cutree(usar.hc.comp, 3)) usar.cut$States = rownames(usar.cut) rownames(usar.cut) = seq(1, nrow(usar.cut)) names(usar.cut)[1] <- "Clusters" usar.cut$Clusters <- factor(usar.cut$Clusters) usar.cut <- dcast(usar.cut, States ~ Clusters) names(usar.cut)[2] = "Cluster 1" names(usar.cut)[3] = "Cluster 2" names(usar.cut)[4] = "Cluster 3" #Output table states/cluster usar.cut
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern