View source: R/general_tools.R
| get_silhouette_mean | R Documentation |
Computes the average silhouette width for a clustering solution using Euclidean distance.
get_silhouette_mean(X, cluster_assignments, n_threads = 1, verbose = FALSE)
X |
A numeric matrix where rows are observations and columns are features. |
cluster_assignments |
An integer vector of cluster assignments, which must be the same length as the number of rows in |
n_threads |
Number of threads to use for parallel processing. |
verbose |
Logical. If |
A single numeric value: the average silhouette score.
This process can be very slow for large matrices if single-threaded. Use multiple threads to take advantage of parallel computation for significantly faster results.
# Preparing the inputs
set.seed(42)
pc_matrix <- matrix(data = rnorm(n = 10000 * 15, sd = 2), nrow = 10000, ncol = 15)
cluster_numbers <- as.integer(runif(n = 10000, min = 1, max = 10))
# Getting the mean silhouette score
n_threads <- parallel::detectCores()
score <- get_silhouette_mean(pc_matrix, cluster_numbers, n_threads)
print(score)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.