not good but great

プログラミング、アート、映画・本の感想について書きます。

sklearnのt-SNEでs-curveのデータを次元圧縮

f:id:naoyashiga:20160425215257p:plain

import matplotlib.pyplot as plt
from sklearn import manifold, datasets

n_points = 1000
X, color = datasets.samples_generator.make_s_curve(n_points, random_state=0)
n_neighbors = 10
n_components = 2

tsne = manifold.TSNE(n_components=n_components, init='pca', random_state=0)
Y = tsne.fit_transform(X)
plt.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.Spectral)
plt.title("t-SNE")

plt.show()

t-SNEが何なのかよくわかっていないが、コード書いてみた。クラスタリングうまくできている気がする。Sの形にも見える。

・参考

Comparison of Manifold Learning methods — scikit-learn 0.17.1 documentation