'ValueError: Metric 'cosine' not valid. Use sorted(sklearn.neighbors.VALID_METRICS['ball_tree'])

I'm trying to use cosine metric with Ball_tree algorithm since my data is of high dimensions. e.g.

nbrs = NearestNeighbors(n_neighbors=2,algorithm='ball_tree',metric='cosine').fit(data_seed)

However i get the following error:

ValueError: Metric 'cosine' not valid. Use sorted(sklearn.neighbors.VALID_METRICS['ball_tree']) to get valid options. Metric can also be a callable function.

I don't understand why i cannot use cosine similarity with ball tree?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source