In [1]:
%matplotlib inline
import numpy as np
import pandas as pd
from sklearn.manifold import MDS
import matplotlib.pyplot as plt
In [2]:
# データの読み込み
data = pd.read_csv("data/tab71.csv", header=None)
labels = ["Urawa", "Chiba", "Tokyo", "Yokohama", "Hachiouji"]
data.head()
Out[2]:
In [3]:
# 古典的MDS
mds = MDS(2, dissimilarity="precomputed")
result = mds.fit_transform(data)
pd.DataFrame(result, index=labels)
Out[3]:
In [4]:
# プロット
plt.scatter(result[:, 0], result[:, 1])
for i in range(result.shape[0]):
plt.text(result[:, 0][i], result[:, 1][i], labels[i], fontsize=12)
plt.title("MDS")
Out[4]: