【发布时间】:2013-12-13 03:40:54
【问题描述】:
我正在使用 e1071 R 包中的 cmeans 对我的数据进行聚类。我想预测新数据的集群成员资格,但我不知道如何编写预测函数。虽然预测硬聚类成员很简单(只需分配到最近的聚类中心),但我不知道如何计算成员值,因为它们在 cl$membership 中给出:
cl <- cmeans( train, centers= 10, m= 1.08 )
# cl$membership contains the "soft" cluster membership
# the following line does not work, unfortunately
cl.new <- predict( cl, test )
# getting the hard cluster assignments is easy
predict.fclust <- function( cl, x ) {
which.cl <- function( xx )
which.min( apply( cl$centers, 1, function( y ) sum( ( y - xx )^2 ) ) )
ret <- apply( x, 1, which.cl )
names( ret ) <- rownames( x )
ret
}
# this works, but only predicts hard clustering
cl.new <- predict( cl, test )
【问题讨论】:
标签: r cluster-analysis