Quantcast
Channel: solem's vision blog
Viewing all articles
Browse latest Browse all 31

Isomap with scikit-learn

$
0
0
The scikit-learn project for Python contains many machine learning algorithms neatly packaged. There are several manifold learning algorithms in the manifold module. Here's a simple example of Isomap on the classic Swiss roll 3D point set.

from pylab import *
from mpl_toolkits.mplot3d import Axes3D
from sklearn import manifold, datasets

"""
Based on scikits.learn example at
http://scikit-learn.org/stable/auto_examples/manifold/plot_swissroll.html
"""

# load Swiss roll dataset
X, color = datasets.samples_generator.make_swiss_roll(n_samples=1500)

# run Isomap on the points in X with 2 dim output
n_neighbors = 10
Y = manifold.Isomap(n_neighbors, 2).fit_transform(X)

# 3D plot
fig = figure()
ax = fig.gca(projection='3d')
ax.scatter(X[:,0], X[:,1], X[:,2], c=color)

# 2D projection
figure()
scatter(Y[:,0], Y[:,1], c=color)

show()

The code generates these plots (3D plotting with Matplotlib/Pylab is explained here).


As you can see Isomap finds a nice 2D manifold. Pretty neat.

Viewing all articles
Browse latest Browse all 31

Trending Articles