中的距离上限参数的度量是什么scipy.space.KDTree。查询?

2024-05-17 01:36:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始使用scipy。我似乎不太明白distance_upper_boundscipy.spatial.KDTree.query中的度量。它是以公里还是弧度?在


Tags: 度量scipyqueryupperspatialdistanceboundkdtree
1条回答
网友
1楼 · 发布于 2024-05-17 01:36:24

它正是使用参数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

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']

相关问题 更多 >