View source: R/agglomerative.R
| cuda_ml_agglomerative_clustering | R Documentation |
Recursively merge the pair of clusters that minimally increases a given linkage distance.
cuda_ml_agglomerative_clustering(
x,
n_clusters = 2L,
metric = c("euclidean", "l1", "l2", "manhattan", "cosine"),
connectivity = c("pairwise", "knn"),
n_neighbors = 15L
)
x |
The input matrix or data frame. Each data point should be a row and should consist of numeric values only. |
n_clusters |
The number of clusters to find. Default: 2L. |
metric |
Metric used for linkage computation. Must be one of {"euclidean", "l1", "l2", "manhattan", "cosine"}. If connectivity is "knn" then only "euclidean" is accepted. Default: "euclidean". |
connectivity |
The type of connectivity matrix to compute. Must be one of {"pairwise", "knn"}. Default: "pairwise".
|
n_neighbors |
The number of neighbors to compute when
|
A clustering object with the following attributes:
"n_clusters": The number of clusters found by the algorithm.
"children": The children of each non-leaf node. Values less than
nrow(x) correspond to leaves of the tree which are the original
samples. children[i + 1][1] and children[i + 1][2] were
merged to form node (nrow(x) + i) in the i-th iteration.
"labels": cluster label of each data point.
library(cuda.ml)
if (interactive() && cuda_ml_backend_info()$runtime_installed) {
library(MASS)
library(purrr)
set.seed(0)
gen_pts <- function() {
centers <- list(c(1000, 1000), c(-1000, -1000), c(-1000, 1000))
pts <- centers |>
map(\(center) mvrnorm(50, mu = center, Sigma = diag(2)))
do.call(rbind, pts)
}
clust <- cuda_ml_agglomerative_clustering(
x = gen_pts(),
metric = "euclidean",
n_clusters = 3
)
print(clust$labels)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.