我正在尝试使用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;
}
}
文件clust.txt包含两列,其中X和Y值用制表符分隔。我尝试了几个不同的数据,我总是得到0.