0
votes

I have a similarity matrix which considers the similarity between each two users among the 80 users. I want to cluster the users based on this similarity matrix.

label = SpectralClustering(n_clusters=5 ,affinity='precomputed').fit_predict(lena)

is this the right way to call the similarity matrix and get the label? example: if we have three users, the matrix like[1,0.8,0;0.8,1,0;0,0,1] and get label like(1,1,2).

Furthermore, I want to use the Elbow method https://en.wikipedia.org/wiki/Determining_the_number_of_clusters_in_a_data_set to set the right number of clusters. But its difficult to have right measurement for the performance. Any suggestions?

1
lena is an image, not a distance matrix. - Has QUIT--Anony-Mousse
@Anony-Moussehttp://scikit-learn.org/stable/modules/generated/sklearn.cluster.SpectralClustering.html. I see what you mean, but on this link, fit_predict(X, y=None)[source] Performs clustering on X and returns cluster labels. Parameters: X : ndarray, shape (n_samples, n_features) Input data. Is that possible to consider each user's similarity between all the others' as the features of that user? Or otherwise, do you know when the affinity = precomputed, where should the precomputed matrix being put? with many thanks - printemp
If it is not lena aka: Lenna but a matrix of yours, don't call the variable lena, please. That is misleading, because this is a very popular example. - Has QUIT--Anony-Mousse

1 Answers

0
votes

Same question here, read the docs of sklearn but remains unclear.

From my investiguations:

given sc = SpectralClustering(n_clusters=5 ,affinity='precomputed')

sc.fit_predict(similarity_matrix) should do the trick. It assigns similarity_matrix to sc.affinity_matrix_ and then performs clustering.