【问题标题】:Plotting k-Means clustering output [closed]绘制 k 均值聚类输出
【发布时间】:2013-10-20 07:17:06
【问题描述】:

我在 java 中使用“k-means”对我的数据集进行了聚类,下面是我的聚类算法的输出。

List<Cluster<T>>  finalClusters = doClustering();

public <T> Cluster(){
   public T centroid;
   public List<T> classifiedPoints
   public int classification ;   
 }

任何类型 T 的类如下

  T {
 double[] attributes;
  }

现在我想像下面这样绘制这个输出,是否有任何 Java 绘图库为此,或者我必须将此输出写入文件并使用 R 绘制它。

【问题讨论】:

  • 不清楚attributes 是什么意思?属性是您的输入数据吗?
  • @agstudy 属性是我的输入数据

标签: java r plot k-means


【解决方案1】:

http://www.jfree.org/jfreechart/

  • 或完全在R 中完成... :)
  • 或使用RServeJava 连接到R,它有一个Java 客户端。您还可以在 SO 中找到相当数量的 questions 标记的所以

【讨论】:

    【解决方案2】:

    您可以使用rJava 将 java 连接到 R。它相对简单。我在下面展示了一个我会使用的场景。

    首先我编写了一个 R 代码来聚类数据并仅使用 R 函数绘制它们。例如,您可以这样做:

    x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
               matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
    colnames(x) <- c("x", "y")
    (cl <- kmeans(x, 2))  ## you replace kmeans by your call to java function
    plot(x, col = cl$cluster)
    points(cl$centers, col = 1:2, pch = 8, cex = 2)
    

    然后你通过调用你的 java 函数来替换对 kmeans 的调用:

     library(rJava)
    .jinit(PATH-TO_YOUR_CLASS_BIN_OR_JAR) # this starts the JVM
     ## I call a the Cluster constructor giving  it the imput data 
     ## Obvsiouly you should create this constructor
     javaCluster <- .jnew("Cluster",.jarray(x,dispatch=TRUE))
     ## call th clustering function which returns a vector of integers
     cl <- .jcall(javaCluster ,"[I",method="doClustering")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 2019-07-29
      • 1970-01-01
      • 2018-04-04
      • 2014-07-24
      • 2015-02-09
      • 2017-12-30
      • 1970-01-01
      相关资源
      最近更新 更多