Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python sklearn KDTree with haversine distance

I try to create a KD tree of WGS84 coordinates and find neighbors within a certain radius

from sklearn.neighbors.dist_metrics import DistanceMetric
from sklearn.neighbors.kd_tree import KDTree    
T = KDTree([[47.8665, 8.90123]], metric=DistanceMetric.get_metric('haversine'))

But get the following error:

ValueError: metric HaversineDistance is not valid for KDTree

How can I use haversine distance in a KD-Tree?

like image 822
user307380 Avatar asked Jul 04 '16 16:07

user307380


1 Answers

The k-d-tree can (to the best of my knowledge) only be used with Minkowski norms.

There are other trees such as the ball tree in sklearn, or the covertree in ELKI that work with Haversine distance because it is a metric.

like image 141
Has QUIT--Anony-Mousse Avatar answered Oct 14 '22 20:10

Has QUIT--Anony-Mousse