相关疑难解决方法(0)

将 sklearn 半正弦输出解释为公里

我不知道如何解释 sklearn(20.2 版)中半正弦实现的输出

文档说,“请注意,半正弦距离度量需要 [纬度,经度] 形式的数据,输入和输出都以弧度为单位。”,所以我应该能够转换为公里乘以 6371(远距离大约为半径)。

两点的功能距离计算如下:

def distance(origin, destination):
    lat1, lon1 = origin
    lat2, lon2 = destination
    radius = 6371 # km

    dlat = math.radians(lat2-lat1)
    dlon = math.radians(lon2-lon1)
    a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \
        * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
    d = radius * c

    return d

distance([32.027240,-81.093190],[41.981876,-87.969982])
1263.103504537151
Run Code Online (Sandbox Code Playgroud)

这是正确的距离。

使用 BallTree 实现:

from sklearn.neighbors import BallTree
test_points = [[32.027240,41.981876],[-81.093190,-87.969982]]
tree = BallTree(test_points,metric = 'haversine')
results = tree.query_radius(test_points,r = 10,return_distance …
Run Code Online (Sandbox Code Playgroud)

python haversine scikit-learn

4
推荐指数
2
解决办法
2264
查看次数

标签 统计

haversine ×1

python ×1

scikit-learn ×1