|
27 | 27 | from sklearn.utils.testing import ignore_warnings
|
28 | 28 | from sklearn.utils.validation import check_random_state
|
29 | 29 |
|
| 30 | +from sklearn.externals.joblib import parallel_backend |
| 31 | + |
30 | 32 | rng = np.random.RandomState(0)
|
31 | 33 | # load and shuffle iris dataset
|
32 | 34 | iris = datasets.load_iris()
|
@@ -1315,6 +1317,24 @@ def test_same_radius_neighbors_parallel(algorithm):
|
1315 | 1317 | assert_array_equal(ind[i], ind_parallel[i])
|
1316 | 1318 | assert_array_almost_equal(graph, graph_parallel)
|
1317 | 1319 |
|
| 1320 | +@pytest.mark.parametrize('backend', ['loky', 'multiprocessing', 'threading']) |
| 1321 | +@pytest.mark.parametrize('algorithm', ALGORITHMS) |
| 1322 | +def test_knn_forcing_backend(backend, algorithm): |
| 1323 | + # Non-regression test which ensure the knn is properly working |
| 1324 | + # even when forcing the global joblib backend |
| 1325 | + with parallel_backend(backend): |
| 1326 | + X, y = datasets.make_classification(n_samples=30, n_features=5, |
| 1327 | + n_redundant=0, random_state=0) |
| 1328 | + X_train, X_test, y_train, y_test = train_test_split(X, y) |
| 1329 | + |
| 1330 | + clf = neighbors.KNeighborsClassifier(n_neighbors=3, |
| 1331 | + algorithm=algorithm, |
| 1332 | + n_jobs=3) |
| 1333 | + clf.fit(X_train, y_train) |
| 1334 | + y = clf.predict(X_test) |
| 1335 | + dist, ind = clf.kneighbors(X_test) |
| 1336 | + graph = clf.kneighbors_graph(X_test, mode='distance').toarray() |
| 1337 | + |
1318 | 1338 |
|
1319 | 1339 | def test_dtype_convert():
|
1320 | 1340 | classifier = neighbors.KNeighborsClassifier(n_neighbors=1)
|
|
0 commit comments