Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sklearn/manifold/spectral_embedding_.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from scipy.linalg import eigh
from scipy.sparse.linalg import eigsh, lobpcg
from scipy.sparse.csgraph import connected_components
from scipy.sparse.csgraph import laplacian as csgraph_laplacian

from ..base import BaseEstimator
from ..externals import six
Expand Down Expand Up @@ -234,8 +235,8 @@ def spectral_embedding(adjacency, n_components=8, eigen_solver=None,
warnings.warn("Graph is not fully connected, spectral embedding"
" may not work as expected.")

laplacian, dd = sparse.csgraph.laplacian(adjacency, normed=norm_laplacian,
return_diag=True)
laplacian, dd = csgraph_laplacian(adjacency, normed=norm_laplacian,
return_diag=True)
if (eigen_solver == 'arpack' or eigen_solver != 'lobpcg' and
(not sparse.isspmatrix(laplacian) or n_nodes < 5 * n_components)):
# lobpcg used with eigen_solver='amg' has bugs for low number of nodes
Expand Down
5 changes: 3 additions & 2 deletions sklearn/manifold/tests/test_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from numpy.testing import assert_array_equal

from scipy import sparse
from scipy.sparse import csgraph
from scipy.linalg import eigh

from sklearn.manifold.spectral_embedding_ import SpectralEmbedding
Expand Down Expand Up @@ -254,8 +255,8 @@ def test_spectral_embedding_unnormalized():
drop_first=False)

# Verify using manual computation with dense eigh
laplacian, dd = sparse.csgraph.laplacian(sims, normed=False,
return_diag=True)
laplacian, dd = csgraph.laplacian(sims, normed=False,
return_diag=True)
_, diffusion_map = eigh(laplacian)
embedding_2 = diffusion_map.T[:n_components] * dd
embedding_2 = _deterministic_vector_sign_flip(embedding_2).T
Expand Down
3 changes: 2 additions & 1 deletion sklearn/semi_supervised/label_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import warnings
import numpy as np
from scipy import sparse
from scipy.sparse import csgraph

from ..base import BaseEstimator, ClassifierMixin
from ..externals import six
Expand Down Expand Up @@ -514,7 +515,7 @@ def _build_graph(self):
self.nn_fit = None
n_samples = self.X_.shape[0]
affinity_matrix = self._get_kernel(self.X_)
laplacian = sparse.csgraph.laplacian(affinity_matrix, normed=True)
laplacian = csgraph.laplacian(affinity_matrix, normed=True)
laplacian = -laplacian
if sparse.isspmatrix(laplacian):
diag_mask = (laplacian.row == laplacian.col)
Expand Down
5 changes: 3 additions & 2 deletions sklearn/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# License: BSD 3 clause

from scipy import sparse
from scipy.sparse import csgraph

from .graph_shortest_path import graph_shortest_path # noqa
from .deprecation import deprecated
Expand Down Expand Up @@ -73,11 +74,11 @@ def single_source_shortest_path_length(graph, source, cutoff=None):
"version 0.19 and will be removed in 0.21. Use "
"scipy.sparse.csgraph.connected_components instead.")
def connected_components(*args, **kwargs):
return sparse.csgraph.connected_components(*args, **kwargs)
return csgraph.connected_components(*args, **kwargs)


@deprecated("sklearn.utils.graph.graph_laplacian was deprecated in version "
"0.19 and will be removed in 0.21. Use "
"scipy.sparse.csgraph.laplacian instead.")
def graph_laplacian(*args, **kwargs):
return sparse.csgraph.laplacian(*args, **kwargs)
return csgraph.laplacian(*args, **kwargs)