Created
October 16, 2019 14:05
-
-
Save Btibert3/441822ea54d7fa5e17c4772ffe70dfb1 to your computer and use it in GitHub Desktop.
A simple function to explore hclust in R to look at distance/cluster tradeoff
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
| ## function to take an dendrogram, and heights for each iteration | |
| ## pull out the # of clusters and height | |
| hclust_eval = function(c) { | |
| # extract the height, and the dendrogram | |
| h = c$height | |
| d = as.dendrogram(c) | |
| # the container for the stats | |
| s = list() | |
| # for each entry in h, get the # of clusters | |
| # TODO: improve this code | |
| for (i in 1:length(h)) { | |
| tmp_h = h[i] | |
| tmp = length(unique(cutree(d, h=tmp_h))) | |
| s[[i]] = list(iteration = i, | |
| n_clust = tmp, | |
| h_dist = tmp_h) | |
| rm(tmp_h, tmp) | |
| } | |
| # return s | |
| return(s) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment