Created
January 23, 2012 21:30
-
-
Save amueller/1665623 to your computer and use it in GitHub Desktop.
Weird kneibors behaviour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import datasets, manifold | |
from sklearn.neighbors import NearestNeighbors | |
import numpy as np | |
n_points = 1000 | |
n_neighbors = 10 | |
out_dim = 2 | |
n_trials = 100 | |
X, _ = datasets.samples_generator.make_s_curve(n_points, random_state=123) | |
for i in xrange(n_trials): | |
knn = NearestNeighbors(n_neighbors + 1).fit(X) | |
print("with return") | |
asdf = knn.kneighbors(X, return_distance=True) # will give no warning | |
print("without return") | |
knn.kneighbors(X, return_distance=True) # will give warning in second go of loop | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
with return
without return
0
with return
without return
1
with return
without return
Traceback (most recent call last):
File "testlle.py", line 15, in
knn.kneighbors(X, return_distance=True) # will give warning in second go of loop
File "/home/amueller/checkout/scikit-learn/sklearn/neighbors/base.py", line 225, in kneighbors
warn_equidistant()
File "/home/amueller/checkout/scikit-learn/sklearn/neighbors/base.py", line 23, in warn_equidistant
raise ValueError
ValueError