python - KD 树最近邻搜索是如何工作的?

标签 python machine-learning nearest-neighbor kdtree

我正在查看 KD 树的维基百科页面。例如,我在 python 中实现了用于构建列出的 kd 树的算法。

但是,使用 KD 树进行 KNN 搜索的算法会切换语言并且并不完全清楚。英文解释开始有意义,但它的一部分(例如他们“展开递归”以检查其他叶节点的区域)对我来说真的没有任何意义。

这是如何工作的,如何在 python 中使用 KD 树进行 KNN 搜索?这不是一个 “请给我发送代码!” 类型的问题,我不希望这样。请做一个简短的解释:)

最佳答案

book introduction , 第 3 页:

Given a set of n points in a d-dimensional space, the kd-tree is constructed recursively as follows. First, one finds a median of the values of the ith coordinates of the points (initially, i = 1). That is, a value M is computed, so that at least 50% of the points have their ith coordinate greater-or-equal to M, while at least 50% of the points have their ith coordinate smaller than or equal to M. The value of x is stored, and the set P is partitioned into PL and PR , where PL contains only the points with their ith coordinate smaller than or equal to M, and |PR | = |PL |±1. The process is then repeated recursively on both PL and PR , with i replaced by i + 1 (or 1, if i = d). When the set of points at a node has size 1, the recursion stops.

以下段落讨论了它在解决最近邻问题中的用途。

或者,这里是 original 1975 paper by Jon Bentley .

编辑:我应该补充一点,SciPy 有一个 kdtree 实现:

关于python - KD 树最近邻搜索是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4418450/

相关文章:

python - 使用 %matplotlib 内联时,Jupyter 笔记本 Canvas 无法交互

python - 仅插入(或外推) Pandas 数据框中的小间隙

python-3.x - 无法从 torchvision.models.resnet 导入 "BasicBlock"

c++ - [OpenCL] 使用欧氏距离的最近邻

python - Python 中的二维最近邻插值

computational-geometry - 使用 Voronoi 图进行最近邻搜索

python - 使用 TensorFlow 和 Keras 进行图像分类

python - python中如果value是key则删除字典的value

machine-learning - Catboost:l2_leaf_reg 的合理值是多少?

machine-learning - 如何调整 L2 正则化