Description Usage Arguments Value Examples
k-Means Clustering for Data on Hypersphere
1 2 3 4 5 6 7 |
x |
an (n\times p) row-stacked matrix for \mathbb{S}^{p-1}. |
k |
the number of clusters to be found. |
init |
method for setting initial configuration. |
maxiter |
maximum number of iterations to be run. |
type |
type of distance, either |
a named list containing
length-n vector of class membership indices.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## generate two-cluster data
mymu1 = c(0,0,0,1) # center of class 1
mymu2 = c(-1,0,0,0) # center of class 2
x1 = rvmf(50, mymu1, kappa=10)
x2 = rvmf(50, mymu2, kappa=10)
xx = rbind(x1,x2)
## apply clustering with different k values
cl2 <- sp.kmeans(xx, k=2)
cl3 <- sp.kmeans(xx, k=3)
cl4 <- sp.kmeans(xx, k=4)
## compute 2-dimensional embedding for visualization
mds2d <- sp.mds(xx, ndim=2)
mdsx <- mds2d$embed[,1]
mdsy <- mds2d$embed[,2]
## compare via visualization
opar <- par(mfrow=c(1,3), pty="s")
plot(mdsx, mdsy, col=cl2$cluster, main="k=2 means", pch=19)
plot(mdsx, mdsy, col=cl3$cluster, main="k=3 means", pch=19)
plot(mdsx, mdsy, col=cl4$cluster, main="k=4 means", pch=19)
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.