多维缩放(MDS)在一个简单的例子中失败

数据挖掘 scikit-学习
2022-02-20 11:04:28

我想对特定对象应用多维缩放(MDS);使用欧几里得距离对此类对象没有意义;使用另一个距离度量,我可以计算它们的相异矩阵D. 然后我使用 sklearn 使用 MDS 计算维度 2 中对象的嵌入:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.manifold import MDS

D = np.array( [ [   0.,  87., 175., 264. ],
                [  87.,   0.,  87., 175. ],
                [ 175.,  87.,   0.,  87. ],
                [ 264., 175.,  87.,   0. ] ])
L = [ "1", "2", "3", "4" ]
embedding = MDS(n_components=2, dissimilarity = "precomputed", random_state = 1235)
X_transformed = embedding.fit_transform(D)
X_transformed.shape

fig = plt.figure( figsize=(10,10), facecolor="white")
ax = fig.add_subplot(1,1,1)
ax.scatter(D[:,0], D[:,1], s = 80)
for i, label in enumerate(L):
    ax.annotate(label, (D[i,0]+10,D[i,1]) )
ax.set_aspect("equal")
fig.set_tight_layout(True)
plt.show()

从形式上可以看出D所有点必须对齐和排序。但是,我得到

MDS 结果

点 1 未正确定位。我该如何补救?感谢您的任何提示。

0个回答
没有发现任何回复~