0

在 R 中使用sparcl包在 R 中执行稀疏层次聚类时,我无法获得数据的聚类标签。在帮助文档中,它们具有以下代码:

# Generate 2-class data
set.seed(1)
x <- matrix(rnorm(100*50),ncol=50)
y <- c(rep(1,50),rep(2,50))
x[y==1,1:25] <- x[y==1,1:25]+2

# Do tuning parameter selection for sparse hierarchical clustering
perm.out <- HierarchicalSparseCluster.permute(x, wbounds=c(1.5,2:6), nperms = 5)

# Perform sparse hierarchical clustering
sparsehc <- HierarchicalSparseCluster(dists=perm.out$dists,
wbound=perm.out$bestw, method="complete")

现在,我的问题是如何从对象sparsehc获取集群标签?

对于 Kmeans,我们创建了一个简单的属性“cs”。例如。

## Choosing tuning parameters
km.perm <- KMeansSparseCluster.permute(data_mat, K = 10, wbounds= seq(3,7, len =
20),     nperms=5)

## Performing kmean sparce clustring 
sparse_data_clus <- KMeansSparseCluster(data_mat, K = 10, wbounds= km.perm$bestw)
clusterlabel <- sparse_data_clus[[1]]$Cs

如何在HierarchicalSparseCluster()中获得类似的标签?

谢谢!

4

2 回答 2

1

层次聚类通常会返回一个树状图(即一个层次的聚类,底部有单个元素,顶部有完整的数据集),而不是严格的划分。

如果您想要严格的分区(例如由常规 k-means 生成),则必须从该层次结构中提取这样的分区。有很多方法可以做到这一点,最简单的是使用阈值水平。

由于我不经常使用 R(太慢),但我无法在此处为您提供详细信息。看看?cutree

于 2013-05-20T10:05:35.253 回答
0

回复这个有点晚了,但我遇到了同样的问题。这对我有用:

set.seed(1)
x <- matrix(rnorm(100*50),ncol=50)
y <- c(rep(1,50),rep(2,50))
x[y==1,1:25] <- x[y==1,1:25]+2
data_mat <- x

对您创建的矩阵进行排列

hier.perm <- HierarchicalSparseCluster.permute(data_mat, 
                                               wbounds= seq(3,7, len = 20),
                                               nperms=5)

运行HierarchicalSparse结果

hier.sparse <- HierarchicalSparseCluster(dists=hier.perm$dists, 
                                         wbound=hier.perm$bestw,
                                         method='complete')

hclust在上一行的值上运行$u,然后根据需要使用cutree它来划分它

cluster = hclust(dist(hier.sparse$u))    
cutree(cluster,3)
于 2014-10-22T00:53:25.053 回答