我正在尝试使用归一化切割执行光谱嵌入/聚类。我编写了以下代码,但我遇到了一个逻辑瓶颈。对特征向量进行聚类后我该怎么办?我不知道如何在我的原始数据集上形成集群。(A是我的亲和力矩阵)
D = np.diag(np.sum(A, 0))
D_half_inv = np.diag(1.0 / np.sqrt(np.sum(A, 0)))
M = np.dot(D_half_inv, np.dot((D - A), D_half_inv))
# compute eigenvectors and eigenvalues
(w, v) = np.linalg.eigh(M)
# renorm eigenvectors to have norm 1
var = len(w)
v1 = np.array(np.zeros((var, var)))
for j in range(var):
v[:][j] = v[:][j]/np.sqrt(np.sum(A,0))
v[:][j] = v[:][j]/np.linalg.norm(v1[:][j])
v_trailing = v[:,1:45] #omit the corresponding eigenvector of the smallest eigenvalue which is 0 and 45 is my embedding dimension
k = 20 #number of clusters
centroids,idx = kmeans2(v_trailing, k)
之后,我得到每个特征向量的标签。但是如何将这些标签链接到我的原始数据集上?