当 precompute_distances 设置为 True 时,k-means 会预先计算哪些距离?
Which distances k-means pre-computes when precompute_distances is set to True?
我正在使用 scikit-learn 运行 k-means。我查看了 scikit-learn k-means 代码,但我不明白 k-means 如何提前预先计算距离。 k-means 在事先不知道中心值的情况下预先计算了哪些距离?
它不会预先计算中心之间的距离,它会预先计算一个点(比如 X)与系统中所有其他点之间的距离,并将它们存储起来以备后用。
检查此 line 619 in kmeans which calls _labels_inertia_precompute_dense
, which in turn calls pairwise_distances_argmin_min at line 562。
pairwise_distances_argmin_min 的文档指出
Compute minimum distances between one point and a set of points.
This function computes for each row in X, the index of the row of Y
which is closest (according to the specified distance). The minimal
distances are also returned.
所以它不需要知道中心,这只是用来预先计算所有可能的点对之间的距离。
我正在使用 scikit-learn 运行 k-means。我查看了 scikit-learn k-means 代码,但我不明白 k-means 如何提前预先计算距离。 k-means 在事先不知道中心值的情况下预先计算了哪些距离?
它不会预先计算中心之间的距离,它会预先计算一个点(比如 X)与系统中所有其他点之间的距离,并将它们存储起来以备后用。
检查此 line 619 in kmeans which calls _labels_inertia_precompute_dense
, which in turn calls pairwise_distances_argmin_min at line 562。
pairwise_distances_argmin_min 的文档指出
Compute minimum distances between one point and a set of points. This function computes for each row in X, the index of the row of Y which is closest (according to the specified distance). The minimal distances are also returned.
所以它不需要知道中心,这只是用来预先计算所有可能的点对之间的距离。