From 2011bf2282bb36207f562cff2d24f15b8a02e9ae Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Tue, 7 Mar 2017 18:04:01 -0500 Subject: [PATCH 01/10] DOCATHON : Make implementation match docs for Isomap --- sklearn/manifold/isomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/manifold/isomap.py b/sklearn/manifold/isomap.py index f649237448d32..6ac431929d309 100644 --- a/sklearn/manifold/isomap.py +++ b/sklearn/manifold/isomap.py @@ -100,7 +100,7 @@ def __init__(self, n_neighbors=5, n_components=2, eigen_solver='auto', self.n_jobs = n_jobs def _fit_transform(self, X): - X = check_array(X) + X = check_array(X, accept_sparse='csr') self.nbrs_ = NearestNeighbors(n_neighbors=self.n_neighbors, algorithm=self.neighbors_algorithm, n_jobs=self.n_jobs) From 7b4e11724b6eb974024554eb44f570b3449b1d4d Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Tue, 7 Mar 2017 18:04:32 -0500 Subject: [PATCH 02/10] DOCATHON : Test for new sparse support in Isomap --- sklearn/manifold/tests/test_isomap.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sklearn/manifold/tests/test_isomap.py b/sklearn/manifold/tests/test_isomap.py index 8006872b78567..8bf7a5cb3cb56 100644 --- a/sklearn/manifold/tests/test_isomap.py +++ b/sklearn/manifold/tests/test_isomap.py @@ -10,6 +10,8 @@ from sklearn import preprocessing from sklearn.utils.testing import assert_less +from scipy.sparse import rand as sparse_rand + eigen_solvers = ['auto', 'dense', 'arpack'] path_methods = ['auto', 'FW', 'D'] @@ -122,3 +124,16 @@ def test_isomap_clone_bug(): model.fit(np.random.rand(50, 2)) assert_equal(model.nbrs_.n_neighbors, n_neighbors) + +def test_sparse_input(): + rand = np.random.RandomState(0) + X = sparse_rand(100, 3, density=0.1, format='csr', + dtype=np.float, random_state=rand) + + # Should not error + for eigen_solver in eigen_solvers: + for path_method in path_methods: + clf = manifold.Isomap(n_components=2, + eigen_solver=eigen_solver, + path_method=path_method) + clf.fit(X) \ No newline at end of file From af4609c8a4c538b0eb886e8a28ea4af8bce9a8cf Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Tue, 7 Mar 2017 18:06:07 -0500 Subject: [PATCH 03/10] DOCATHON : Docs for LLE were incorrect; fix them. --- sklearn/manifold/locally_linear.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sklearn/manifold/locally_linear.py b/sklearn/manifold/locally_linear.py index 2d3257bf54be3..b8bcd39fa8fc6 100644 --- a/sklearn/manifold/locally_linear.py +++ b/sklearn/manifold/locally_linear.py @@ -69,10 +69,9 @@ def barycenter_kneighbors_graph(X, n_neighbors, reg=1e-3, n_jobs=1): Parameters ---------- - X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors} + X : array-like Sample data, shape = (n_samples, n_features), in the form of a - numpy array, sparse array, precomputed tree, or NearestNeighbors - object. + numpy array. n_neighbors : int Number of neighbors for each sample. @@ -194,10 +193,9 @@ def locally_linear_embedding( Parameters ---------- - X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors} + X : array-like Sample data, shape = (n_samples, n_features), in the form of a - numpy array, sparse array, precomputed tree, or NearestNeighbors - object. + numpy array. n_neighbors : integer number of neighbors to consider for each point. From 017ee18f1c41feba9e2d3b04f9893f68b8f0a1ae Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Tue, 7 Mar 2017 19:30:47 -0500 Subject: [PATCH 04/10] Older versions of scipy sparse don't support random_state --- sklearn/manifold/tests/test_isomap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/manifold/tests/test_isomap.py b/sklearn/manifold/tests/test_isomap.py index 8bf7a5cb3cb56..46ffb74b2b103 100644 --- a/sklearn/manifold/tests/test_isomap.py +++ b/sklearn/manifold/tests/test_isomap.py @@ -126,9 +126,8 @@ def test_isomap_clone_bug(): n_neighbors) def test_sparse_input(): - rand = np.random.RandomState(0) X = sparse_rand(100, 3, density=0.1, format='csr', - dtype=np.float, random_state=rand) + dtype=np.float) # Should not error for eigen_solver in eigen_solvers: From 952b9828bc7e67029802b44cf6e90c1879a90c85 Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Tue, 7 Mar 2017 19:33:09 -0500 Subject: [PATCH 05/10] Some versions of scipy don't like 'float' dtype ro sparse rand. --- sklearn/manifold/tests/test_isomap.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/manifold/tests/test_isomap.py b/sklearn/manifold/tests/test_isomap.py index 46ffb74b2b103..b166f0a31056b 100644 --- a/sklearn/manifold/tests/test_isomap.py +++ b/sklearn/manifold/tests/test_isomap.py @@ -126,8 +126,7 @@ def test_isomap_clone_bug(): n_neighbors) def test_sparse_input(): - X = sparse_rand(100, 3, density=0.1, format='csr', - dtype=np.float) + X = sparse_rand(100, 3, density=0.1, format='csr') # Should not error for eigen_solver in eigen_solvers: From 72ec9c577571a2fe28ddf12295cc5ca08bba9fb9 Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Tue, 7 Mar 2017 20:37:48 -0500 Subject: [PATCH 06/10] Flake8 compliance. --- sklearn/manifold/tests/test_isomap.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/manifold/tests/test_isomap.py b/sklearn/manifold/tests/test_isomap.py index b166f0a31056b..d1a68164ee45c 100644 --- a/sklearn/manifold/tests/test_isomap.py +++ b/sklearn/manifold/tests/test_isomap.py @@ -125,6 +125,7 @@ def test_isomap_clone_bug(): assert_equal(model.nbrs_.n_neighbors, n_neighbors) + def test_sparse_input(): X = sparse_rand(100, 3, density=0.1, format='csr') @@ -134,4 +135,4 @@ def test_sparse_input(): clf = manifold.Isomap(n_components=2, eigen_solver=eigen_solver, path_method=path_method) - clf.fit(X) \ No newline at end of file + clf.fit(X) From 6917759915b80c43fb656dd596d2a954b524c408 Mon Sep 17 00:00:00 2001 From: Leland McInnes Date: Fri, 10 Mar 2017 09:48:20 -0500 Subject: [PATCH 07/10] DOC : Add types back into docstring per comments. --- sklearn/manifold/locally_linear.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/manifold/locally_linear.py b/sklearn/manifold/locally_linear.py index b8bcd39fa8fc6..44d00a025758a 100644 --- a/sklearn/manifold/locally_linear.py +++ b/sklearn/manifold/locally_linear.py @@ -69,7 +69,7 @@ def barycenter_kneighbors_graph(X, n_neighbors, reg=1e-3, n_jobs=1): Parameters ---------- - X : array-like + X : {array-like, BallTree, KDTree, NearestNeighbors} Sample data, shape = (n_samples, n_features), in the form of a numpy array. @@ -193,7 +193,7 @@ def locally_linear_embedding( Parameters ---------- - X : array-like + X : {array-like, BallTree, KDTree, NearestNeighbors} Sample data, shape = (n_samples, n_features), in the form of a numpy array. From 31f8e876f13728e878cc92a584b2ecae6a3e4e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Fri, 29 Jun 2018 05:33:52 +0200 Subject: [PATCH 08/10] Restore docstring to a more correct version --- sklearn/manifold/locally_linear.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/manifold/locally_linear.py b/sklearn/manifold/locally_linear.py index 44d00a025758a..661af1d4166a6 100644 --- a/sklearn/manifold/locally_linear.py +++ b/sklearn/manifold/locally_linear.py @@ -69,9 +69,9 @@ def barycenter_kneighbors_graph(X, n_neighbors, reg=1e-3, n_jobs=1): Parameters ---------- - X : {array-like, BallTree, KDTree, NearestNeighbors} + X : {array-like, NearestNeighbors} Sample data, shape = (n_samples, n_features), in the form of a - numpy array. + numpy array or a NearestNeighbors object. n_neighbors : int Number of neighbors for each sample. @@ -193,9 +193,9 @@ def locally_linear_embedding( Parameters ---------- - X : {array-like, BallTree, KDTree, NearestNeighbors} + X : {array-like, NearestNeighbors} Sample data, shape = (n_samples, n_features), in the form of a - numpy array. + numpy array or a NearestNeighbors object. n_neighbors : integer number of neighbors to consider for each point. From 3ed93ec9f12a652739e42a9a43e5e3dcee3c7602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Fri, 29 Jun 2018 08:56:56 +0200 Subject: [PATCH 09/10] Add whats_new entry --- doc/whats_new/v0.20.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats_new/v0.20.rst b/doc/whats_new/v0.20.rst index 802976c2b380c..cddeab1eb93b3 100644 --- a/doc/whats_new/v0.20.rst +++ b/doc/whats_new/v0.20.rst @@ -326,6 +326,9 @@ Decomposition and manifold learning :class:`manifold.TSNE`. :issue:`10593` and :issue:`10610` by `Tom Dupre la Tour`_. +- Support sparse input in :meth:`manifold.Isomap.fit`. :issue:`8554` by + :user:`lmcinnes`. + Metrics - :func:`metrics.roc_auc_score` now supports binary ``y_true`` other than From 88885c2c654727f950cfa6071574957699802882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Mon, 2 Jul 2018 11:06:17 +0200 Subject: [PATCH 10/10] Add user name --- doc/whats_new/v0.20.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats_new/v0.20.rst b/doc/whats_new/v0.20.rst index cddeab1eb93b3..342a5c1c39bda 100644 --- a/doc/whats_new/v0.20.rst +++ b/doc/whats_new/v0.20.rst @@ -327,7 +327,7 @@ Decomposition and manifold learning `Tom Dupre la Tour`_. - Support sparse input in :meth:`manifold.Isomap.fit`. :issue:`8554` by - :user:`lmcinnes`. + :user:`Leland McInnes `. Metrics