clustring

Est West Airlines

mydata<-read.csv("E:\\EXCELR ASSIGMENTS\\assignment\\EastWestAirlines.csv")
View(mydata)
#library(readxl)
mydata1<-mydata[1:100,c(2:12)]
View(mydata1)
normalized_data<-scale(mydata1) 
View(normalized_data)

d<-dist(normalized_data,method="euclidean")
as.matrix(d)[1:10,1:10]
##             1          2          3          4         5          6
## 1   0.0000000  0.1511333  0.4043215  0.1626507  5.223891  0.1992109
## 2   0.1511333  0.0000000  0.3848077  0.1198453  5.178611  0.2217342
## 3   0.4043215  0.3848077  0.0000000  0.4774250  4.971476  0.5651212
## 4   0.1626507  0.1198453  0.4774250  0.0000000  5.230154  0.1124326
## 5   5.2238911  5.1786108  4.9714761  5.2301543  0.000000  5.2935582
## 6   0.1992109  0.2217342  0.5651212  0.1124326  5.293558  0.0000000
## 7   3.3519883  3.2851448  3.0127909  3.3662288  3.249418  3.4558057
## 8   2.1880881  2.1705278  2.1626157  2.1814653  4.343691  2.2019777
## 9  13.1497499 13.1364351 13.0139346 13.1831878 11.624746 13.2152539
## 10  4.4204404  4.3630763  4.1399559  4.4323101  1.437423  4.5071771
##            7         8        9        10
## 1   3.351988  2.188088 13.14975  4.420440
## 2   3.285145  2.170528 13.13644  4.363076
## 3   3.012791  2.162616 13.01393  4.139956
## 4   3.366229  2.181465 13.18319  4.432310
## 5   3.249418  4.343691 11.62475  1.437423
## 6   3.455806  2.201978 13.21525  4.507177
## 7   0.000000  3.703029 12.35225  2.522527
## 8   3.703029  0.000000 12.76937  3.454140
## 9  12.352250 12.769375  0.00000 11.632390
## 10  2.522527  3.454140 11.63239  0.000000
fit<-hclust(d,method="complete")
#?hclust
plot(fit) # Display Dendrogram

plot(fit,hang=-1)
groups<-cutree(fit,k=5)

#?cutree
rect.hclust(fit,k=5,border="red")

#?rect.hclust

membership<-as.matrix(groups)

final<-data.frame(mydata1,membership)
final1<-final[,c(ncol(final),1:(ncol(final)-1))]
View(final1)

#install.packages("data.table")
#library(data.table)