I noticed that there are two different functions for spectral clustering in sklearn.cluster library: SpectralClustering and spectral_clustering. Although they differ in some details, both do spectral clustering and most of their parameters overlap. I am confused about why there are two methods so similar in sklearn?
Some differences I noticed:
In SpectralClustering, parameter
affinity
takes both string and array; its default value is'rbf'
; in spectral_clustering it can only be a matrixSpectralClustering() works like a constructor. It doesn't return anything but has two attributes
affinity_matrix_
(which you can access after calling .fit()) andlabels_
. spectral_clustering is a method that only returns the labels.
Using SpectralClustering:
cluster=SpectralClustering().fit(X)
cluster.labels_
Using spectral_clustering:
labels=spectral_clustering(affinity_matrix)
Despite these apparent differences, I'm wondering whether these two methods differ in fundamental aspects. Otherwise why are there two methods that accomplish basically the same thing?
SpectralClustering
basically computes the affinity matrix by itself and then callsspectral_clustering(Affinity_Matrix)
. – Kylander