【发布时间】:2020-08-02 17:09:01
【问题描述】:
我正在对 1000*1000 的相似度矩阵进行谱聚类。我的相似度矩阵如下:
matrix([[0.000, 0.031, 0.030, ..., 0.850, 0.867, 0.838],
[0.031, 0.000, 0.005, ..., 0.780, 0.805, 0.781],
[0.030, 0.005, 0.000, ..., 0.803, 0.823, 0.795],
...,
[0.850, 0.780, 0.803, ..., 0.000, 0.024, 0.008],
[0.867, 0.805, 0.823, ..., 0.024, 0.000, 0.014],
[0.838, 0.781, 0.795, ..., 0.008, 0.014, 0.000]])
我创建了邻接矩阵和度矩阵以及拉普拉斯矩阵,然后计算了特征值和特征向量,并使用第二小的特征值来确定应该将哪个节点放在哪个类别中。:
e, v = np.linalg.eig(L)
fig = plt.figure(figsize=[30, 6])
ax1 = plt.subplot(221)
plt.plot(e)
ax1.title.set_text('eigenvalues')
i = np.where(e < 300)[0]
ax2 = plt.subplot(222)
plt.plot(v[:, i[0]])
ax3 = plt.subplot(223)
plt.plot(v[:, i[1]])
ax3.title.set_text('second eigenvector with eigenvalue close to 0')
但是当我想按如下方式运行 kmeans 来分隔点时,我遇到了错误:
U = np.array(v[:, i[1]])
km = KMeans(init='k-means++', n_clusters=3)
km.fit(U)
km.labels_
错误:
> ValueError: 不支持复杂数据 [[-0.04866435+0.j] [-0.04909432+0.j] [-0.04840705+0.j] [-0.04859193+0.j] [-0.0514795 +0.j],...]
你能帮我知道为什么会出现这个错误吗?我搜索了很多,但没有结果。
【问题讨论】:
标签: python cluster-analysis valueerror complex-data-types