Sie sind auf Seite 1von 1

install.

packages('dendextend')
library('dendextend')

getwd()
dir()

library(xlsx)
input <- read.xlsx("EastWestAirlinesCluster.xlsx",sheetName = "data",header=TRUE)
dim(input)

mydata <- input[2:12] ## exclude the columns with university and state names

nput3 <- input[sample(nrow(mydata), replace = F, size = 0.95*nrow(input)),]

normalized_data1 <- scale(mydata)


normalized_data2 <- scale(nput3) ## normalize the columns

## Hierarchical Clustering

?dist ## computes the distance matrix


?hclust ## runs hierarchical clustering

## Aproach 1: Euclidean distance, Single linkage


d1 <- dist(normalized_data1, method = "euclidean")
d2 <- dist(normalized_data2, method = "euclidean")
fit1 <- hclust(d1, method="ward.D")
fit2 <- hclust(d2, method="ward.D")
#fit <- hclust(d, method="single")
plot(fit) # display dendrogram

dend1 <- as.dendrogram(fit1)


d1=color_branches(dend1,k=2)
plot(d1)

dend2 <- as.dendrogram(fit2)


d2=color_branches(dend2,k=2)
plot(d2)

Das könnte Ihnen auch gefallen