k-Medoids Clustering for Data on Hypersphere
1 | sp.kmedoids(x, k = 2, type = c("intrinsic", "extrinsic"))
|
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=5)
x2 = rvmf(50, mymu2, kappa=10)
xx = rbind(x1,x2)
## apply clustering with different k values
cl2 <- sp.kmedoids(xx, k=2)
cl3 <- sp.kmedoids(xx, k=3)
cl4 <- sp.kmedoids(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 medoids", pch=19)
plot(mdsx, mdsy, col=cl3$cluster, main="k=3 medoids", pch=19)
plot(mdsx, mdsy, col=cl4$cluster, main="k=4 medoids", pch=19)
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.