Created
June 29, 2018 06:16
-
-
Save benjamin-chan/ff2adddb2cbcdc044038d6f7525cf769 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("cluster") | |
install.packages("ggdendro") | |
install.packages("factoextra") | |
library(cluster) | |
library(ggdendro) | |
library(factoextra) | |
hc <- | |
df %>% | |
select(-id) %>% | |
select(-starts_with("PCB")) %>% | |
agnes(method= "ward") | |
hc | |
hc %>% ggdendrogram() | |
df %>% | |
select(-id) %>% | |
select(-starts_with("PCB")) %>% | |
fviz_nbclust(FUN = hcut, method = "wss") | |
df %>% | |
select(-id) %>% | |
select(-starts_with("PCB")) %>% | |
fviz_nbclust(FUN = hcut, method = "silhouette") | |
df %>% | |
select(-id) %>% | |
select(-starts_with("PCB")) %>% | |
clusGap(FUN = hcut, nstart = 25, K.max = 10, B = 50) %>% | |
fviz_gap_stat() | |
clusterID <- hc %>% cutree(k = 4) | |
table(clusterID) | |
hc | |
plot(hc, ask = FALSE, which.plots = 2) | |
rect.hclust(hc, k = 4, border = 2:8) | |
df0 <- | |
df %>% | |
mutate(clusterID = hc %>% cutree(k = 4)) | |
hc_a <- agnes(df, method = "ward") | |
cutree(as.hclust(hc_a), k = 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment