Ignore:
Timestamp:
02/07/12 22:10:30 (2 years ago)
Author:
Miha Stajdohar <miha.stajdohar@…>
Branch:
default
rebase_source:
47b37dfeeee4ff6a7f33d4ba04c055bbd6a1ee1e
Message:

Missing some methods from another example.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/hierarchical-example-2.py

    r9906 r10008  
    66distance = Orange.distance.Euclidean(iris) 
    77for i1, instance1 in enumerate(iris): 
    8     for i2 in range(i1+1, len(iris)): 
     8    for i2 in range(i1 + 1, len(iris)): 
    99        matrix[i1, i2] = distance(instance1, iris[i2]) 
    10          
     10 
    1111clustering = Orange.clustering.hierarchical.HierarchicalClustering() 
    1212clustering.linkage = clustering.Average 
    1313clustering.overwrite_matrix = 1 
    1414root = clustering(matrix) 
     15 
     16def prune(cluster, togo): 
     17    if cluster.branches: 
     18        if togo < 0: 
     19            cluster.branches = None 
     20        else: 
     21            for branch in cluster.branches: 
     22                prune(branch, togo - cluster.height) 
     23 
     24def listOfClusters0(cluster, alist): 
     25    if not cluster.branches: 
     26        alist.append(list(cluster)) 
     27    else: 
     28        for branch in cluster.branches: 
     29            listOfClusters0(branch, alist) 
     30 
     31def listOfClusters(root): 
     32    l = [] 
     33    listOfClusters0(root, l) 
     34    return l 
     35tables = [Orange.data.Table(cluster) for cluster in listOfClusters(root)] 
    1536 
    1637prune(root, 1.4) 
     
    2546        print "%s: %3.0f " % (iris.domain.class_var.values[e], d), 
    2647    print 
    27  
    28 tables = [Orange.data.Table(cluster) for cluster in listOfClusters(root)] 
Note: See TracChangeset for help on using the changeset viewer.