gpt4 book ai didi

python - SKlearn : KDTree how to return nearest neighbour based on threshold (Python)

转载 作者:行者123 更新时间:2023-12-01 09:34:33 30 4
gpt4 key购买 nike

我有一个包含 300 张图像的数据库,我为每张图像提取了一个 BOVW。从查询图像(从同一字典中提取 query_BOVW)开始,我需要在训练数据集中找到类似的图像。

我在训练集上使用了 Sklearn KDTree kd_tree = KDTree(training),然后使用 kd_tree.query(query_vector) 计算与查询向量的距离。最后一个函数将要返回的最近邻居的数量作为第二个参数,但我寻求的是为欧几里得距离设置一个阈值,并根据该阈值有不同数量的最近邻居。

我查看了文档,但没有找到任何相关内容。我寻求一些可能毫无意义的东西是错误的吗?

感谢您的帮助。

最佳答案

您想使用query_radius在这里。

query_radius(self, X, r, count_only = False):

query the tree for neighbors within a radius r

...

只是上面链接中的示例:

import numpy as np
np.random.seed(0)
X = np.random.random((10, 3)) # 10 points in 3 dimensions
tree = BinaryTree(X, leaf_size=2)
print(tree.query_radius(X[0], r=0.3, count_only=True))

ind = tree.query_radius(X[0], r=0.3)
print(ind) # indices of neighbors within distance 0.3

关于python - SKlearn : KDTree how to return nearest neighbour based on threshold (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49650149/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com