我正在尝试使用 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。