Skip to content

Conversation

@ixjlyons
Copy link
Contributor

The documentation for the mode argument of radius_neighbors_graph and kneighbors_graph states that if 'distance' is specified, the matrix returned contains the Euclidean distances between neighbors, but actually the distances calculated according to metric are returned.

Example:

from sklearn import neighbors

X = [[0, 0], [1, 1], [2, 2]]
w1 = neighbors.radius_neighbors_graph(X, 2, mode='distance', metric='manhattan')
w2 = neighbors.kneighbors_graph(X, 1, mode='distance', metric='manhattan')

print(w1.toarray())
print(w2.toarray())

Output:

[[ 0.  2.  0.]
 [ 2.  0.  2.]
 [ 0.  2.  0.]]
[[ 0.  2.  0.]
 [ 2.  0.  0.]
 [ 0.  2.  0.]]

@jnothman
Copy link
Member

thanks!

@jnothman jnothman merged commit 97b90fb into scikit-learn:master Apr 24, 2016
@ixjlyons ixjlyons deleted the fix-neighbor-docs branch April 26, 2016 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants