2024-05-17 01:36:24 发布
网友
我刚开始使用scipy。我似乎不太明白distance_upper_bound在scipy.spatial.KDTree.query中的度量。它是以公里还是弧度?在
distance_upper_bound
scipy.spatial.KDTree.query
它正是使用参数p决定的所选度量的值。在
p
如果你选择了p=1,也就是曼哈顿距离,x=[1,2,3]和{}的距离是3。如果您使用distance_upper_bound=2,并且y是您要查找的x的下一个邻居,那么不要期望得到正确的结果。在
p=1
x=[1,2,3]
3
distance_upper_bound=2
y
x
备注:您所说的这个参数默认设置为inf。在
inf
您的任务似乎是关于纬度/经度点的。在本例中,我认为您希望使用Haversine-metric(免责声明:我不是这方面的专家)。在
遗憾的是,这个度量在a p-norm中是不可用的,scipy的邻居搜索只支持这个度量!在
但是:sklearn的BallTree可以和Haversine一起工作!(KDTree没有!还是p规范!)在
KDTree不支持Haversine,而BallTree支持Haversine,可能有一个很好的原因(无论是数学还是实际性能)。不要试图盲目地滚动你自己的Haversine KDTree!在
从here:
A binary search tree cannot handle the wraparound of the polar representation by design. You might need to transform the coordinates to a 3D cartesian space and then apply your favorite search algorithm, e.g., kD-Tree, Octree etc.
from sklearn.neighbors import KDTree, BallTree KDTree.valid_metrics # ['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', # 'infinity'] BallTree.valid_metrics # ['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', # 'infinity', 'seuclidean', 'mahalanobis', 'wminkowski', 'hamming', 'canberra', # 'braycurtis', 'matching', 'jaccard', 'dice', 'kulsinski', 'rogerstanimoto', 'russellrao', # 'sokalmichener', 'sokalsneath', 'haversine', 'pyfunc']
它正是使用参数
p
决定的所选度量的值。在如果你选择了}的距离是
p=1
,也就是曼哈顿距离,x=[1,2,3]
和{3
。如果您使用distance_upper_bound=2
,并且y
是您要查找的x
的下一个邻居,那么不要期望得到正确的结果。在备注:您所说的这个参数默认设置为
inf
。在您的任务似乎是关于纬度/经度点的。在本例中,我认为您希望使用Haversine-metric(免责声明:我不是这方面的专家)。在
遗憾的是,这个度量在a p-norm中是不可用的,scipy的邻居搜索只支持这个度量!在
但是:sklearn的BallTree可以和Haversine一起工作!(KDTree没有!还是p规范!)在
KDTree不支持Haversine,而BallTree支持Haversine,可能有一个很好的原因(无论是数学还是实际性能)。不要试图盲目地滚动你自己的Haversine KDTree!在
从here:
相关问题 更多 >
编程相关推荐