def cluster(aff_matrix, records, n_clusters, medoid_indexes):
Cluster = SpectralClustering(n_clusters=n_clusters, affinity='precomputed')
labels = Cluster.fit_predict(aff_matrix)
medoid_indexes = medoid_indexes.loc[records]
t_records = []
indexes = []
for i in range(n_clusters):
labels_i = np.where(labels == i)[0]
sub_aff_matrix = aff_matrix[labels_i, :][:, labels_i]
medoid_index = np.argmax(np.prod(sub_aff_matrix, axis=0))
absolute_index = labels_i[medoid_index]
r = medoid_indexes.index[absolute_index]
t_records.append(r)
i = medoid_indexes.iloc[absolute_index].values[0]
indexes.append(i)
return t_records, indexes
评论列表
文章目录