KDTree should support Haversine Metric
See original GitHub issueRelated to #12552
Using the Haversine metric with the KDTree produces an error
haversineMetric = DistanceMetric.get_metric('haversine')
coordsKdTree = KDTree(coords, leaf_size =1e3, metric = haversineMetric)
ValueError Traceback (most recent call last)
<ipython-input-15-fa4421f977f6> in <module>
10 #Create KD tree with haversine metric
11 haversineMetric = DistanceMetric.get_metric('haversine')
---> 12 coordsKdTree = KDTree(coords, leaf_size =1e3, metric = haversineMetric)
sklearn/neighbors/_binary_tree.pxi in sklearn.neighbors._kd_tree.BinaryTree.__init__()
ValueError: metric HaversineDistance is not valid for KDTree
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
python sklearn KDTree with haversine distance - Stack Overflow
Which tells, you can't use haversine with KDTree. The reason behind it is haversine distance gives you Orthodromic distance which is the ...
Read more >Using Scikit-learn's Binary Trees to Efficiently Find Latitude ...
To use a ball tree with the Haversine distance in scikit-learn, you must first convert the coordinates from degrees to radians. # Creates...
Read more >Benchmarking Nearest Neighbor Searches in Python
I recently submitted a scikit-learn pull request containing a brand new ball tree and kd-tree for fast nearest neighbor searches in python.
Read more >Nearest neighbor analysis with large datasets - Read the Docs
Note: There is also an algorithm called KDTree in scikit-learn, that is also highly efficient but less flexible in terms of supported distance...
Read more >sklearn.neighbors.KDTree — scikit-learn 1.2.0 documentation
Note: Callable functions in the metric parameter are NOT supported for KDTree: and Ball Tree. Function call overhead will result in very poor...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Though it was added to Ball Tree by Jake at the time of the original implementation (https://github.com/scikit-learn/scikit-learn/commit/01fce7661632c7898feaf9a2e1dc3ce97a91473d, https://github.com/scikit-learn/scikit-learn/pull/1732) and none of the reviewers disagreed. So maybe we are missing something. I guess we could always try to find an counter-example to the triangle inequality with Haversine distance to be sure 😃
My math on the sphere is pretty bad, and it sounds like you are right 😃
Thanks for investigating! Probably safter to keep this closed then (though the latter part needs better citations ^^)?