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

Skip to content
3 changes: 3 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:`Leland McInnes <lmcinnes>`.

Metrics

- :func:`metrics.roc_auc_score` now supports binary ``y_true`` other than
Expand Down
2 changes: 1 addition & 1 deletion sklearn/manifold/isomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions sklearn/manifold/locally_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, NearestNeighbors}
Sample data, shape = (n_samples, n_features), in the form of a
numpy array, sparse array, precomputed tree, or NearestNeighbors
object.
numpy array or a NearestNeighbors object.

n_neighbors : int
Number of neighbors for each sample.
Expand Down Expand Up @@ -194,10 +193,9 @@ def locally_linear_embedding(

Parameters
----------
X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors}
X : {array-like, NearestNeighbors}
Sample data, shape = (n_samples, n_features), in the form of a
numpy array, sparse array, precomputed tree, or NearestNeighbors
object.
numpy array or a NearestNeighbors object.

n_neighbors : integer
number of neighbors to consider for each point.
Expand Down
14 changes: 14 additions & 0 deletions sklearn/manifold/tests/test_isomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -122,3 +124,15 @@ def test_isomap_clone_bug():
model.fit(np.random.rand(50, 2))
assert_equal(model.nbrs_.n_neighbors,
n_neighbors)


def test_sparse_input():
X = sparse_rand(100, 3, density=0.1, format='csr')

# 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)