ELKI 获取聚类数据点

ELKI get clustering data points

当我使用 elki 时,如何获取 kmeans (llyod) 集群中的 数据点 centroid

我也可以将这些点插入距离函数之一并获得任意两个点之间的距离吗?

这个问题不同,因为我的问题的主要焦点是检索数据点,而不是自定义数据点。此外,另一个线程上的答案目前还不完整,因为它指的是目前无法正常运行的 wiki。此外,我想具体知道需要做什么,因为所有库的文档有点像徒劳的追逐,如果您 know/understand 库,您将非常感激直接有了答案,这样其他有同样问题的人也可以有一个很好的可靠参考来参考,而不是试图找出图书馆。

一个Cluster (JavaDoc) in ELKI never stores the point data. It only stores point DBIDs (Wiki), which you can get using the getIDs() method. To get the original data, you need the Relation from your database. The method getModel() returns the cluster model, which for kmeans is a KMeansModel.

你可以通过他们DBID从数据库Relation中获取点数据, 或根据两个 DBIDs.

计算距离

KMeans 的质心很特殊——它不是数据库对象,而是总是一个数值向量——簇的算术平均值。使用 KMeans 时,您应该使用 SquaredEuclideanDistanceFunction. This is a NumberVectorDistanceFunction,它具有方法 distance(NumberVector o1, NumberVector o2)(并非所有距离都适用于数字向量!)。

Relation<? extends NumberVector> rel = ...;
NumberDistanceFunction df = SquaredEuclideanDistanceFunction.STATIC;

... run the algorithm, then iterate over each cluster: ...

Cluster<KMeansModel> cluster = ...;
Vector center = cluster.getModel().getMean(); 
double varsum = cluster.getModel().getVarianceContribution();

double sum = 0.;
// C++-style for loop, for efficiency:
for(DBIDRef id = cluster.getIDs().iterDBIDs(); id.valid(); id.advance()) {
   double distance = df.distance(relation.get(id), center);
   sum += distance;
}

System.out.println(varsum+" should be the same as "+sum);