source: orange/orange/doc/modules/hclust-iris.py @ 6773:76ec6754d30b

Revision 6773:76ec6754d30b, 873 bytes checked in by blaz <blaz.zupan@…>, 4 years ago (diff)

long-forgotten demo script for hierarhical clustering

Line 
1import orange
2import orngClustering
3import pylab
4
5def plot_scatter(data, cls, attx, atty, filename="hclust-scatter", title=None):
6    """plot a data scatter plot with the position of centeroids"""
7    pylab.rcParams.update({'font.size': 8, 'figure.figsize': [4,3]})
8    x = [float(d[attx]) for d in data]
9    y = [float(d[atty]) for d in data]
10    colors = ["c", "w", "b"]
11    cs = "".join([colors[c] for c in cls])
12    pylab.scatter(x, y, c=cs, s=10)
13   
14    pylab.xlabel(attx)
15    pylab.ylabel(atty)
16    if title:
17        pylab.title(title)
18    pylab.savefig("%s.png" % filename)
19    pylab.close()
20
21data = orange.ExampleTable("iris")
22root = orngClustering.hierarchicalClustering(data)
23n = 3
24cls = orngClustering.hierarhicalClustering_topClustersMembership(root, n)
25plot_scatter(data, cls, "sepal width", "sepal length", title="Hiearchical clustering (%d clusters)" % n)
Note: See TracBrowser for help on using the repository browser.