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
Store spectral embeddings in SpectralClustering #26061
Comments
@matteo-bastico it would help us decide if you could explain how you would use this. |
As a workaround, you may recompute the mapping after fitting from sklearn.cluster import SpectralClustering
from sklearn.manifold import spectral_embedding
import numpy as np
X = np.array([[1, 1], [2, 1], [1, 0],
[4, 7], [3, 5], [3, 6]])
clustering = SpectralClustering(n_clusters=2,
assign_labels='discretize',
random_state=0).fit(X)
maps = spectral_embedding(
clustering.affinity_matrix_,
n_components=clustering.n_clusters,
eigen_solver=clustering.eigen_solver,
random_state=0,
eigen_tol=clustering.eigen_tol,
drop_first=False,
) |
In my case, I want to compute the medoids of the clusters using the distances in the spectral embedding space instead of the original Euclidean space. But there are others applications in which this feature can be useful.
Thank you, as a workaround it works but the spectral embeddings are computed twice and for large matrices it is time consuming. |
Describe the workflow you want to enable
Save the spectral embeddings used for clustering in the SpectralClustering class and make them accessible through an attribute, e.g.
maps_
, to make easier post-processing on the clusters.Describe your proposed solution
Optionally return the maps in the spectral_clustering method with a new parameter:
Store
maps_
attribute in thefit
method of theSpectralClustering
class:Describe alternatives you've considered, if relevant
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: