2

I want to apply multi-dimensional scaling (MDS) on specific objects; using the Euclidean distance does not make sense for such objects; using another distance metric, I can compute their dissimilarity matrix $D$. Then I compute the embeddings of the objects in dimension 2 with MDS using sklearn:

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()

It is obvious from the form of $D$ that all points must be aligned and ordered. However, I get

MDS result

The point 1 is not correctly positioned. How can I remedy this ? thanks for any hint.

user11634
  • 21
  • 1

0 Answers0