Last active
July 10, 2017 03:09
-
-
Save GINK03/2a2fbd85a732ac79982b1619d50f85f6 to your computer and use it in GitHub Desktop.
python3-scikilearn-lle-manifold
This file contains hidden or 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 matplotlib.pyplot as plt | |
# This import is needed to modify the way figure behaves | |
from mpl_toolkits.mplot3d import Axes3D | |
#---------------------------------------------------------------------- | |
# Locally linear embedding of the swiss roll | |
from sklearn import manifold, datasets | |
X, color = datasets.samples_generator.make_swiss_roll(n_samples=1500) | |
print("Computing LLE embedding") | |
X_r, err = manifold.locally_linear_embedding(X, n_neighbors=12, | |
n_components=2) | |
print("Done. Reconstruction error: %g" % err) | |
#---------------------------------------------------------------------- | |
# Plot result | |
fig = plt.figure() | |
try: | |
# compatibility matplotlib < 1.0 | |
ax = fig.add_subplot(211, projection='3d') | |
ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=color, cmap=plt.cm.Spectral) | |
except: | |
ax = fig.add_subplot(211) | |
ax.scatter(X[:, 0], X[:, 2], c=color, cmap=plt.cm.Spectral) | |
ax.set_title("Original data") | |
ax = fig.add_subplot(212) | |
ax.scatter(X_r[:, 0], X_r[:, 1], c=color, cmap=plt.cm.Spectral) | |
plt.axis('tight') | |
plt.xticks([]), plt.yticks([]) | |
plt.title('Projected data') | |
plt.show() |
This file contains hidden or 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
matplotlib==2.0.2 | |
scikit_learn==0.18.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment