-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Fix for spectral clustering error when using 'amg' solver #13707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a0f1f7b
change AMG tolerance default & laplacian shift (fixes #13393)
whitews 6e5ecf6
add spectral clustering test for AMG solver
whitews d61cf3b
update docs with edits from Andrew Knyazev (& some fixed)
whitews b0c4356
revert tolerance value changes, not needed for AMG solver fix
whitews 0c8390b
update v0.21 changelog noting #13393 fix
whitews f64decb
simplify diag correction in spectral_embedding
whitews cf126b2
revert the reversion: increased tolerances are required
whitews d9fc5ee
use importorskip instead of try/except clause for availability of pyamg
whitews 1f544ea
reference issue in amg solver failure test
whitews 5a3a058
clarify random seed change for spectral embedding amg failure test
whitews bba21b0
Merge branch 'master' into spec-clust-amg-fix
whitews 346cff0
leave original tolerance for 'lobpcg' eigen solver
whitews 98b17ec
implement original shift code from lobpcg, add comment
whitews 302850c
Merge branch 'master' into spec-clust-amg-fix
whitews 2eed15e
fix long line
whitews 783e6e4
only shift laplacian for the solver, then un-shift back to original
whitews 65bf8e9
Merge branch 'master' into spec-clust-amg-fix
jnothman 4a2e3df
Update sklearn/manifold/spectral_embedding_.py
whitews 0362c39
remove noinspection comment
whitews f46f91b
removing spectral clustering bug text
whitews 61d54de
add spectral clustering fix contribution
whitews c48fbe0
fix markup in last commit
whitews 95f2a99
Merge branch 'master' of https://github.com/scikit-learn/scikit-learn…
whitews a452c95
mention SpectralEmbedding & SpectralClustering classes in release notes
whitews e601a8c
oMerge remote-tracking branch 'origin/master' into spec-clust-amg-fix
ogrisel de645ba
Update AMG docstring and improve codestyle
ogrisel 0501603
Stricter check in pyamg test
ogrisel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,10 +162,7 @@ def test_spectral_embedding_callable_affinity(seed=36): | |
|
||
def test_spectral_embedding_amg_solver(seed=36): | ||
# Test spectral embedding with amg solver | ||
try: | ||
from pyamg import smoothed_aggregation_solver # noqa | ||
except ImportError: | ||
raise SkipTest("pyamg not available.") | ||
pytest.importorskip('pyamg') | ||
|
||
se_amg = SpectralEmbedding(n_components=2, affinity="nearest_neighbors", | ||
eigen_solver="amg", n_neighbors=5, | ||
|
@@ -193,6 +190,32 @@ def test_spectral_embedding_amg_solver(seed=36): | |
assert _check_with_col_sign_flipping(embed_amg, embed_arpack, 1e-5) | ||
|
||
|
||
def test_spectral_embedding_amg_solver_failure(seed=36): | ||
# Test spectral embedding with amg solver failure, see issue #13393 | ||
pytest.importorskip('pyamg') | ||
|
||
# The generated graph below is NOT fully connected if n_neighbors=3 | ||
n_samples = 200 | ||
n_clusters = 3 | ||
n_features = 3 | ||
centers = np.eye(n_clusters, n_features) | ||
S, true_labels = make_blobs(n_samples=n_samples, centers=centers, | ||
cluster_std=1., random_state=42) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be check separately norm_laplacian = False and norm_laplacian = True . The latter is the default, the only option currently checked. |
||
se_amg0 = SpectralEmbedding(n_components=3, affinity="nearest_neighbors", | ||
eigen_solver="amg", n_neighbors=3, | ||
random_state=np.random.RandomState(seed)) | ||
embed_amg0 = se_amg0.fit_transform(S) | ||
|
||
for i in range(10): | ||
se_amg0.set_params(random_state=np.random.RandomState(seed + 1)) | ||
embed_amg1 = se_amg0.fit_transform(S) | ||
|
||
assert _check_with_col_sign_flipping(embed_amg0, embed_amg1, 0.05) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:the behavior of nmi will " | ||
"change in version 0.22") | ||
def test_pipeline_spectral_clustering(seed=36): | ||
# Test using pipeline to do spectral clustering | ||
random_state = np.random.RandomState(seed) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.