Created
May 11, 2016 16:43
-
-
Save neksa/40fe65cdf8fd8c0637e5660846258be7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn import manifold | |
%matplotlib inline | |
D = np.array([[0, 10, 6], [10, 0, 5], [6, 5, 0]]) | |
M = manifold.MDS(n_components=2, n_init=1, max_iter=10000, metric=True, dissimilarity="precomputed") | |
K = M.fit_transform(D) | |
print("Stress", M.stress_) | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
ax.patch.set_facecolor('white') | |
ax.scatter(K[...,0], K[...,1], c=("red", "green", "blue"), s=120, edgecolors='none') | |
ax.set_autoscale_on(False) | |
ax.axis('square') | |
ax.set_xlabel('R1') | |
ax.set_ylabel('R2') | |
fig.suptitle("MDS") | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment