Created
June 19, 2014 12:36
-
-
Save kaizu/2bcc06a4ac7dad1c4c39 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
# -*- coding: utf-8 -*- | |
import numpy | |
data = [] | |
x = numpy.linspace(0.0, 10.0, 100) | |
data.extend([numpy.sin(x) + numpy.random.uniform(-0.5, 0.5, 100) for _ in range(5)]) | |
data.extend([numpy.cos(x) + numpy.random.uniform(-0.5, 0.5, 100) for _ in range(5)]) | |
numpy.random.shuffle(data) | |
import matplotlib.pylab as pylab | |
plt.matshow(numpy.asarray(data), aspect='auto', origin='lower', cmap='hot') | |
plt.show() | |
from scipy.spatial.distance import pdist, squareform | |
from scipy.cluster.hierarchy import linkage, dendrogram | |
dist = squareform(pdist(data, metric='euclidean')) | |
dend = dendrogram(linkage(dist, method='complete')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://nbviewer.ipython.org/github/herrfz/dataanalysis/blob/master/week3/hierarchical_clustering.ipynb