View source: R/build_clusters.R
build.clusters | R Documentation |
This function generates variables groups of relation information that was obtained by var.relations function applying getLinkCommunities.
build.clusters(rel, hcmethod = "ward.D")
rel |
a list containing variables, surr.res, threshold, and var. This is the output of var.relations function. |
hcmethod |
the hierarchical clustering method that is used. (see getLinkCommunities) |
a data frame containing the variable names and their associated clusters.
# read data
data("SMD_example_data")
# get trees and variable names
x = SMD_example_data[,2:ncol(SMD_example_data)]
y = SMD_example_data[,1]
allvariables = colnames(x)# extract variables names
nvar = length(allvariables) # count number of variables
set.seed(42)
RF = ranger::ranger(data = SMD_example_data, dependent.variable.name = "y", num.trees = 10, keep.inbag = TRUE,mtry = floor(nvar^(3/4)), min.node.size = 1)
trees = getTreeranger(RF = RF, ntree = 10)
trees.lay = addLayer(trees)
trees.surr = addSurrogates(RF = RF, trees = trees.lay, s = 10, Xdata = x, num.threads = NULL)
# investigate variable relations
rel=var.relations(forest = list(trees = trees.surr, allvariables = allvariables), variables = allvariables, candidates = allvariables, t = 10)
groups = build.clusters(rel)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.