source: orange/docs/reference/rst/code/hierarchical-example-2.py @ 9906:77274e331dbb

Revision 9906:77274e331dbb, 937 bytes checked in by lanumek, 2 years ago (diff)

Test scrip for hierarchical clustering.

Line 
1import Orange
2
3iris = Orange.data.Table("iris")
4matrix = Orange.misc.SymMatrix(len(iris))
5matrix.setattr("objects", iris)
6distance = Orange.distance.Euclidean(iris)
7for i1, instance1 in enumerate(iris):
8    for i2 in range(i1+1, len(iris)):
9        matrix[i1, i2] = distance(instance1, iris[i2])
10       
11clustering = Orange.clustering.hierarchical.HierarchicalClustering()
12clustering.linkage = clustering.Average
13clustering.overwrite_matrix = 1
14root = clustering(matrix)
15
16prune(root, 1.4)
17for n, cluster in enumerate(listOfClusters(root)):
18    print "\n\n Cluster %i \n" % n
19    for instance in cluster:
20        print instance
21
22for cluster in listOfClusters(root):
23    dist = Orange.statistics.distribution.Distribution(iris.domain.class_var, cluster)
24    for e, d in enumerate(dist):
25        print "%s: %3.0f " % (iris.domain.class_var.values[e], d),
26    print
27
28tables = [Orange.data.Table(cluster) for cluster in listOfClusters(root)]
Note: See TracBrowser for help on using the repository browser.