【问题标题】:R - Predicting custom clusteringR - 预测自定义聚类
【发布时间】:2013-01-24 01:18:36
【问题描述】:

我已经实现了自己的聚类算法,我需要知道的是如何使我的聚类可以通过默认方法“predict”用于预测测试集实例的聚类归属。 我有训练集,我根据它们制作集群,我得到一个代表集群中心的新对象,并且对于训练集的每个实例,他的集群;现在我想使用“预测”将测试集的每个实例分配给他自己的集群

【问题讨论】:

  • 你确定你没有混淆 classificationclustering

标签: r cluster-analysis


【解决方案1】:

基本思路是:

# clustering function
myclust <- function(x){
  ret <- list(x=x)
  class(ret) <- "mycluster" # your class name
  ret
}

# predict function for your class
predict.mycluster <- function(obj){
  result <- obj$x
  return(result)
}

# clustering
y <- myclust(1:4)
class(y)
# [1] "mycluster"
predict(y)
# [1] 1 2 3 4

【讨论】:

    猜你喜欢
    • 2016-02-10
    • 2011-12-28
    • 2015-05-20
    • 1970-01-01
    • 2016-07-12
    • 2012-07-09
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多