You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support Haversine distance in NearestNeighbors #12552
I mean #4453 proposes to implement it in pairwise_distances as a solution, but by changing the logic for algorithm='auto' to pick ball_tree in this case (which is the default algorithm in most cases already) we could make it work with minimal effort.
Though for the sake of consistency (and code logic simplicity), maybe it's still better to add it pairwise_distances using DistanceMetric.get_metric('haversine').pairwise.
We need to check if this happens for other metrics as well.
Hi I've been using sklearn, and now I would like to start contributing. I would like to work on this if no one has started yet. If so, can one of you help me get started?
@rth I am reading the code and I have a couple of "solution", but would be better merge #4458. This will fix this issue.
If you consider necessary I can make a PR to fix this issue changing the logic for algorithm=autoto pick ball_tree. But I don't know if this is a correct solution.
This issue is a result of how algorithm = 'auto' is handled. It seems that NeighborsBase opts for a 'brute' approach when n_neighbors is large relative to the number of samples, and 'brute' does not presently admit 'haversine' as a valid metric.
ifself._fit_method=='auto':
# A tree approach is better for small number of neighbors,# and KDTree is generally faster when availableif ((self.n_neighborsisNoneorself.n_neighbors<self._fit_X.shape[0] //2) andself.metric!='precomputed'):
ifself.effective_metric_inVALID_METRICS['kd_tree']:
self._fit_method='kd_tree'elif (callable(self.effective_metric_) orself.effective_metric_inVALID_METRICS['ball_tree']):
self._fit_method='ball_tree'else:
self._fit_method='brute'else:
self._fit_method='brute'
Because of this, I don't think hard-coding alg_check will work to evade the call specified by ._fit_method == 'brute'.
I agree that resolving #4453 seems like the way to go.
Though for the sake of consistency (and code logic simplicity), maybe it's still better to add it pairwise_distances using DistanceMetric.get_metric('haversine').pairwise.
Let's do it. I would be interested in doing it for all metrics not directly implemented in metrics.pairwise, but I'd be worried about what happens when there are metrics of the same name across scipy.spatial and neighbors.DistanceMetric
Activity
[-]Support Haversine distance in NearestNeighbours[/-][+]Support Haversine distance in NearestNeighbors[/+]rth commentedon Nov 9, 2018
I mean #4453 proposes to implement it in
pairwise_distancesas a solution, but by changing the logic foralgorithm='auto'to pickball_treein this case (which is the default algorithm in most cases already) we could make it work with minimal effort.rth commentedon Nov 9, 2018
Though for the sake of consistency (and code logic simplicity), maybe it's still better to add it
pairwise_distancesusingDistanceMetric.get_metric('haversine').pairwise.We need to check if this happens for other metrics as well.
eamanu commentedon Nov 9, 2018
@rth yes IMO is most easy go for change the logic to pick ball_tree when algo is 'auto'. But, is so simple than write
?
EshwarSR commentedon Nov 9, 2018
Hi I've been using sklearn, and now I would like to start contributing. I would like to work on this if no one has started yet. If so, can one of you help me get started?
eamanu commentedon Nov 9, 2018
@rth I am reading the code and I have a couple of "solution", but would be better merge #4458. This will fix this issue.
If you consider necessary I can make a PR to fix this issue changing the logic for algorithm=
autoto pickball_tree. But I don't know if this is a correct solution.asberk commentedon Nov 10, 2018
This issue is a result of how
algorithm = 'auto'is handled. It seems that NeighborsBase opts for a'brute'approach whenn_neighborsis large relative to the number of samples, and'brute'does not presently admit'haversine'as a valid metric.Because of this, I don't think hard-coding
alg_checkwill work to evade the call specified by._fit_method == 'brute'.I agree that resolving #4453 seems like the way to go.
jnothman commentedon Nov 12, 2018
Let's do it. I would be interested in doing it for all metrics not directly implemented in metrics.pairwise, but I'd be worried about what happens when there are metrics of the same name across scipy.spatial and neighbors.DistanceMetric