Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e75ea28

Browse files
committed
minor update
1 parent 9c112cb commit e75ea28

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

doc/modules/neighbors.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,9 @@ include the precomputation in a pipeline:
544544
>>> from sklearn.neighbors import KNeighborsTransformer
545545
>>> from sklearn.pipeline import make_pipeline
546546
>>> estimator = make_pipeline(
547-
KNeighborsTransformer(n_neighbors=5, mode='distance'),
548-
Isomap(neighbors_algorithm='precomputed'),
549-
memory='/path/to/cache')
547+
... KNeighborsTransformer(n_neighbors=5, mode='distance'),
548+
... Isomap(neighbors_algorithm='precomputed'),
549+
... memory='/path/to/cache')
550550

551551
Second, these transformers give finer control on the nearest neighbors
552552
estimation, for instance enabling multiprocessing though the parameter `n_jobs`.

examples/neighbors/neighbors_in_pipeline_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def run_benchmark():
144144
n_iter = 250
145145
perplexity = 30
146146
# TSNE requires a certain number of neighbors which depends on the
147-
# perplexity parameter
147+
# perplexity parameter
148148
n_neighbors = int(3. * perplexity + 1)
149149

150150
transformers = {

sklearn/manifold/tests/test_t_sne.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_pipeline_with_nearest_neighbors_transformer():
172172
X = rng.randn(20, 2)
173173

174174
# XXX: This test currently fail for euclidean metric since it's not squared
175-
for metric in ['minkowski']:
175+
for metric in ['minkowski', 'sqeuclidean']:
176176

177177
# compare the chained version and the compact version
178178
est_chain = make_pipeline(

sklearn/neighbors/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _kneighbors_from_graph(graph, n_neighbors):
196196
this_dist = graph.data[idx]
197197
this_ind = graph.indices[idx]
198198
# sort neigh_dist and neigh_ind to have increasing distances
199-
perm = np.argsort(neigh_dist)
199+
perm = np.argsort(this_dist)
200200
neigh_dist[i] = this_dist[perm][:n_neighbors]
201201
neigh_ind[i] = this_ind[perm][:n_neighbors]
202202
return neigh_dist, neigh_ind

sklearn/neighbors/classification.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import numpy as np
1212
from scipy import stats
13-
import scipy.sparse as sp
1413
from ..utils.extmath import weighted_mode
1514

1615
from .base import \

sklearn/neighbors/tests/test_neighbors.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,15 @@ def test_precomputed_sparse_invalid():
201201
dist = np.array([[0., 2., 0.], [2., 0., 3.], [0., 3., 0.]])
202202
dist_csr = csr_matrix(dist)
203203
neigh.fit(dist_csr)
204-
assert_raises_regex(ValueError, "Not enough neighbors in"
205-
" .* to get 2 nearest neighbors.*", neigh.kneighbors,
206-
None, n_neighbors=2)
204+
msg = "2 neighbors per samples are required, but some samples have only 1"
205+
assert_raises_regex(ValueError, msg, neigh.kneighbors, None, n_neighbors=2)
207206

208207
# Checks error with inconsistent distance matrix
209208
dist = np.array([[5., 2., 1.], [-2., 0., 3.], [1., 3., 0.]])
210209
dist_csr = csr_matrix(dist)
211-
assert_raises_regex(ValueError, "Not a valid distance"
212-
" .*non-negative values.*", neigh.kneighbors,
213-
dist_csr, n_neighbors=1)
210+
msg = "Not a valid distance .*non-negative values.*"
211+
assert_raises_regex(ValueError, msg, neigh.kneighbors, dist_csr,
212+
n_neighbors=1)
214213

215214

216215
def test_precomputed_cross_validation():

0 commit comments

Comments
 (0)