View source: R/spectral.clust.R
spectral.clust | R Documentation |
This function calculates performs spectral clustering with the k-means step using precomputed similarity or distance matrices, and returns a vector of cluster assignments.
spectral.clust(S, k, nstart = 10, iter.max = 1000,
is.sim = NULL, neighbours = 10)
S |
a |
k |
integer value specifying the number of clusters to form. This is passed to
the |
nstart |
integer value specifying the number of random starts for the bandwidth estimation. Defaults to 3 or the number of variables, whichever is larger. |
iter.max |
integer value specifying the maximum number of iterations for the
|
is.sim |
logical value indicating whether the input matrix |
neighbours |
integer value specifying the number of nearest neighbours to consider when
constructing the graph Laplacian. This helps in determining the structure
of the graph from the similarity or distance matrix. Defaults to |
spectral.clust
implements spectral clustering on pairwise similarity or
distance matrices, following the method described by Ng et al. (2001). The
function first constructs an adjacency matrix from the input similarity or
distance matrix S
using the neighbours
parameter to define the
nearest connections. If S
is a similarity matrix (is.sim = TRUE
),
the function retains the largest values corresponding to the neighbours
nearest observations. If S
is a distance matrix (is.sim = FALSE
),
it retains the smallest values for the nearest observations. The adjacency
matrix is symmetrized and used to compute the unnormalized Laplacian matrix.
The eigenvectors corresponding to the smallest eigenvalues of the Laplacian
are extracted and clustered using the kmeans
algorithm. The number of
clusters, k
, and parameters such as the number of random starts
(nstart
) and maximum iterations (iter.max
) for the kmeans
step are user-specified.
spectral.clust
returns a list
object with the following components:
clusters |
an |
S |
the original |
John R. J. Thompson john.thompson@ubc.ca, Jesse S. Ghashti jesse.ghashti@ubc.ca
Ng, A., Jordan, M., & Weiss, Y. (2001). On spectral clustering: Analysis and an algorithm. “Advances in Neural Information processing systems”, 14.
mscv.dkps
, dkps
, mscv.dkss
,
dkss
, link{kss}
# load the Iris dataset
dat <- iris[,-5]
# calculate pairwise similarities using maximum likelihood cross validation
S <- kss(dat, bw = "np", npmethod = "cv.ml", cFUN = "c_gaussian", verbose = TRUE)
# cluster points using spectral clustering and compare to true class labels
cl <- spectral.clust(S$similarities, 3, is.sim = TRUE)
table(cl$clusters, iris[,5])
# try a different number of neighbours
cl2 <- spectral.clust(S$similarities, 3, is.sim = TRUE, neighbours = 4)
table(cl2$clusters, iris[,5])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.