input<-read.csv("E:\\Data science\\aug25.csv")
View(input)
mydata<-input[1:25,c(1,3,5:9)]
View(mydata)
normalized_data<-scale(mydata[,3:7])
View(normalized_data)
d<-dist(normalized_data,method="euclidean")
d
## 1 2 3 4 5 6 7
## 2 3.5031911
## 3 2.5795306 4.0651758
## 4 0.9438620 3.0958034 2.1507452
## 5 0.6973381 3.7155178 1.9884628 0.9602818
## 6 1.0262314 2.5532779 2.4719730 0.8777947 1.3086487
## 7 0.7802118 2.8766211 2.2902580 0.7833415 0.8785157 0.6520549
## 8 0.9777728 3.9014700 2.0470894 0.9439494 0.7421583 1.4668458 1.3068998
## 9 1.5705055 2.1989733 3.2173801 1.3826524 2.0160030 0.9199553 1.2803178
## 10 3.1882340 1.9462953 2.6242276 2.4686907 3.0376990 2.3838720 2.4799509
## 11 1.3796068 2.2783769 2.5738854 1.2898601 1.5975405 0.6030026 0.8341699
## 12 1.1735135 3.2743194 1.6475138 1.0599324 0.7503176 1.1776539 0.8077079
## 13 1.3157492 4.2571596 1.7717647 1.5835155 0.7002906 1.9109887 1.5013596
## 14 4.0309630 6.6515701 3.2051367 3.8683061 3.4690436 4.6107523 4.2047579
## 15 1.5223466 2.5000570 2.9574672 1.4790828 1.9267702 0.7635247 1.3939767
## 16 5.7207205 7.9620311 4.2821707 5.5316309 5.0756285 6.1971584 5.7456053
## 17 1.0928749 2.5097344 2.8296802 0.9435418 1.4805310 0.6244962 0.7369985
## 18 4.8774472 7.5865653 4.5035052 4.9091628 4.3757373 5.6068831 5.0602258
## 19 1.6085091 4.6734448 2.8606698 2.1977320 1.3519970 2.4584568 1.9008136
## 20 1.9361247 3.2564110 1.5988902 1.4356288 1.4938317 1.8261842 1.3996997
## 21 3.0326874 5.4647962 2.0439683 2.9896552 2.3659650 3.5247577 3.0220370
## 22 1.0611915 3.2490889 1.5946468 0.7754429 0.6681441 1.0338737 0.7566427
## 23 1.6496435 4.6254754 1.8559939 1.8635152 1.0357446 2.3041029 1.8657319
## 24 4.1415294 6.4445373 2.6751129 3.9174863 3.4910438 4.5634485 4.1770184
## 25 1.6737046 1.9339737 3.1631566 1.4604341 2.0366551 0.9594454 1.1950079
## 8 9 10 11 12 13 14
## 2
## 3
## 4
## 5
## 6
## 7
## 8
## 9 2.1637425
## 10 3.1467780 2.5478655
## 11 1.9413520 0.9382423 2.2824615
## 12 1.1238456 2.0007898 2.4454388 1.3902663
## 13 1.0691474 2.6783728 3.4084404 2.1369267 1.0549332
## 14 3.3126502 5.2263249 5.1746146 4.9187876 3.6948575 3.0777487
## 15 1.9249345 1.0066599 2.7136468 1.0146329 1.8423474 2.4723286 5.1849902
## 16 5.0664054 6.8531907 6.2841634 6.3919356 5.1405254 4.5861888 2.0379771
## 17 1.7142160 0.5807823 2.4943821 0.7662744 1.4982868 2.1549195 4.7170798
## 18 4.4730280 6.1071455 6.2648154 5.8045741 4.6912257 3.9973797 1.9313639
## 19 1.8642162 2.9989128 4.0767745 2.6003037 1.8107334 1.2310815 3.3819741
## 20 1.8723881 2.2992638 2.0664907 1.8101815 1.1860735 1.7215640 3.5661884
## 21 2.5960737 4.2067711 4.1169776 3.6508548 2.4570683 1.8543294 1.9090820
## 22 0.9314144 1.8382606 2.4272534 1.3030100 0.3791380 1.0752893 3.6686600
## 23 1.2612810 3.0457745 3.6603304 2.5510736 1.3859953 0.4525997 2.6580960
## 24 3.4056079 5.2684513 4.8354463 4.8059498 3.5369758 3.0130442 1.0712485
## 25 2.2688236 0.4861119 2.2708082 0.8574592 1.8888867 2.6871024 5.2356607
## 15 16 17 18 19 20 21
## 2
## 3
## 4
## 5
## 6
## 7
## 8
## 9
## 10
## 11
## 12
## 13
## 14
## 15
## 16 6.8172464
## 17 1.1260566 6.3299130
## 18 6.2647951 2.2629680 5.5641779
## 19 3.0529784 4.8406790 2.4523535 3.7232029
## 20 2.5405765 4.8149463 1.8450045 4.4052340 2.2565009
## 21 4.1755786 2.8666693 3.6629343 2.5953013 2.1829151 2.2791053
## 22 1.6828884 5.1807927 1.3573928 4.7249150 1.9302671 1.1735076 2.5256288
## 23 2.8795542 4.1852005 2.5072279 3.5734025 1.2155632 1.8800303 1.5156628
## 24 5.1385555 1.7504633 4.7623911 2.5151089 3.5369781 3.3723609 1.5966295
## 25 1.2247367 6.7874838 0.6230478 6.0711680 2.9547579 2.1242105 4.1330217
## 22 23 24
## 2
## 3
## 4
## 5
## 6
## 7
## 8
## 9
## 10
## 11
## 12
## 13
## 14
## 15
## 16
## 17
## 18
## 19
## 20
## 21
## 22
## 23 1.4172208
## 24 3.5485909 2.6402991
## 25 1.8034752 3.0491226 5.2325302
fit<-hclust(d,method="complete")
plot(fit)

plot(fit,hang=-1)
groups<-cutree(fit,k=5)
groups
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## 1 2 3 1 1 2 1 1 2 2 2 1 1 4 2 5 2 5 1 3 4 1 1 4 2
rect.hclust(fit,k=5,border="red")

fit1<-hclust(d,method="centroid")
plot(fit1)

plot(fit1,hang=-1)

membership<-as.data.frame(groups)
View(membership)
final<-data.frame(membership,input)
View(final)
fit$cluster
## NULL
aggregate(input[,3:8],by=list(final$groups),FUN=mean)
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
## returning NA
## Group.1 Univ State SAT Top10 Accept SFRatio
## 1 1 NA NA 1273.500 83.00000 33.40000 12.80000
## 2 2 NA NA 1368.750 90.62500 23.62500 9.37500
## 3 3 NA NA 1275.000 68.50000 54.50000 11.00000
## 4 4 NA NA 1115.333 47.66667 63.66667 16.33333
## 5 5 NA NA 1040.000 38.50000 78.50000 22.00000