Silhouette plot in R

后端 未结 1 1648
既然无缘
既然无缘 2021-01-12 10:34

I have a set of data containing: item, associated cluster, silhouette coefficient. I can further augment this data set with more information if necessary.

I would li

相关标签:
1条回答
  • 2021-01-12 11:05

    Function silhouette in package cluster can do the plots for you. It just needs a vector of cluster membership (produced from whatever algorithm you choose) and a dissimilarity matrix (probably best to use the same one used in producing the clusters). For example:

    library (cluster)
    library (vegan)
    data(varespec)
    dis = vegdist(varespec)
    res = pam(dis,3) # or whatever your choice of clustering algorithm is
    sil = silhouette (res$clustering,dis) # or use your cluster vector
    windows() # RStudio sometimes does not display silhouette plots correctly
    plot(sil)
    

    EDIT: For k-means (which uses squared Euclidean distance)

    library (vegan)
    library (cluster)
    data(varespec)
    dis = dist(varespec)^2
    res = kmeans(varespec,3)
    sil = silhouette (res$cluster, dis)
    windows() 
    plot(sil)
    
    0 讨论(0)
提交回复
热议问题