0

我正在尝试使用 apache.commons.math3.ml.clustering 中的 DBSCANClusterer。函数集群返回集群列表,但对我来说,列表的大小始终为 0。我做错了什么?下面是我的测试代码:

public class ClusterTest {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        DBSCANClusterer dbscan = new DBSCANClusterer(.05, 15);
        List<DoublePoint> points = getData();
        List<Cluster<DoublePoint>> cluster = dbscan.cluster(points);
        for(Cluster<DoublePoint> p : cluster)
            System.out.println(p.getPoints().toString());                             
    }

    private static List<DoublePoint> getData() throws FileNotFoundException, IOException {
        List<DoublePoint> data = new ArrayList<DoublePoint>();      
        BufferedReader reader = new BufferedReader(new FileReader(new File("clust.txt")));
        String line;
        double[] d = new double[2];
        while ((line = reader.readLine()) != null) {
            try {                   
                String[] l = line.split("\t");
                d[0] = Double.parseDouble(l[0]);
                d[1] = Double.parseDouble(l[1]);
                data.add(new DoublePoint(d));
            } catch (Exception e) { }
        }       
        return data;
    }
}

文件 cluster.txt 包含两列,其中 X 和 Y 值用制表符分隔。我尝试了一些不同的数据,但我总是得到 0。

4

1 回答 1

1

请尝试使用ELKI中的版本。不幸的是,Apache commons 数学不是很好。由于各种小问题,我离开了公共数学。ELKI 对我来说效果更好。

快速浏览一下,在聚类分析方面,commons-math 仍然很死......它最后一次被触及MATH-917。那里的 DBSCAN 代码效率仍然很低。在之前的版本中,DBSCAN 使用了所有已弃用的类。但它在 x 年内收到了 4 次提交。

如果你没有得到任何集群,你可能有一个太小的 epsilon,一个太高的 minPts 值......并且DBSCAN 的 commons-math 实现丢失了所有噪声对象- 这就是你可能得到的:所有噪声.

于 2014-12-07T16:47:31.897 回答