Changeset 7281:fc201451ca5d in orange


Ignore:
Timestamp:
02/03/11 00:07:33 (3 years ago)
Author:
blaz <blaz.zupan@…>
Branch:
default
Convert:
59bbd6b81161d74262e4193efc25fd711ac2bad8
Message:

some more documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/projection/som.py

    r7261 r7281  
    2121 
    2222   import Orange 
    23    som = Orange.projection.som.SOMLearner(map_shape=(10, 20), initialize=Orange.projection.som.InitializeRandom) 
     23   som = Orange.projection.som.SOMLearner(map_shape=(8, 8), initialize=Orange.projection.som.InitializeRandom) 
    2424   data = Orange.data.table("iris.tab") 
    2525   map = som(data) 
     
    3737Supervised Learning with Self-Organizing Maps 
    3838============================================= 
     39 
     40Supervised learning requires class-labeled data. For training, 
     41class information is first added to data instances as a regular feature  
     42by extending the feature vectors accordingly. Next, the map is trained, and the 
     43training data projected to nodes. Each node then classifies to the majority class. 
     44For classification, the data instance is projected the cell, returning the associated class. 
     45An example of the code that trains and then classifies on the same data set is:: 
     46 
     47    import Orange 
     48    import random 
     49    learner = Orange.projection.som.SOMSupervisedLearner(map_shape=(4, 4)) 
     50    data = Orange.data.Table("iris.tab") 
     51    classifier = learner(data) 
     52    random.seed(50) 
     53    for d in random.sample(data, 5): 
     54        print "%-15s originally %-15s" % (classifier(d), d.getclass()) 
    3955 
    4056.. autoclass:: SOMSupervisedLearner 
     
    4460Supporting Classes 
    4561================== 
     62 
     63Class :obj:`Map` stores the self-organizing map composed of :obj:`Node` objects. 
    4664 
    4765.. autoclass:: Map 
     
    5573======== 
    5674 
    57 The following code runs k-means clustering and prints out the cluster indexes for the last 10 data instances (`kmeans-run.py`_, uses `iris.tab`_): 
    58  
    59 .. literalinclude:: code/som1.py 
     75The following code  (`code/som-mapping.py`_, uses `iris.tab`_) infers self-organizing map from Iris data set. The map is rather small, and consists  
     76of only 9 cells. We optimize the network, and then report how many data instances were mappped 
     77into each cell. The second part of the code reports on data instances from one of the corner cells: 
     78 
     79.. literalinclude:: code/som-mapping.py 
    6080 
    6181The output of this code is:: 
    6282 
    63     [1, 1, 2, 1, 1, 1, 2, 1, 1, 2] 
     83    Node    Instances 
     84    (0, 0)  21 
     85    (0, 1)  1 
     86    (0, 2)  23 
     87    (1, 0)  22 
     88    (1, 1)  7 
     89    (1, 2)  6 
     90    (2, 0)  32 
     91    (2, 1)  16 
     92    (2, 2)  22 
     93     
     94    Data instances in cell (1, 2): 
     95    [4.9, 2.4, 3.3, 1.0, 'Iris-versicolor'] 
     96    [5.0, 2.0, 3.5, 1.0, 'Iris-versicolor'] 
     97    [5.6, 2.9, 3.6, 1.3, 'Iris-versicolor'] 
     98    [5.7, 2.6, 3.5, 1.0, 'Iris-versicolor'] 
     99    [5.5, 2.4, 3.7, 1.0, 'Iris-versicolor'] 
     100    [5.0, 2.3, 3.3, 1.0, 'Iris-versicolor'] 
     101 
    64102 
    65103""" 
     
    70108import numpy.ma as ma 
    71109import orange 
     110import random 
     111 
     112random.seed(42) 
    72113 
    73114HexagonalTopology = 0 
     
    162203            min, max = numpy.zeros(dimension), numpy.ones(dimension) 
    163204        for node in self: 
    164             node.vector = min + numpy.random.rand(dimension) * (max - min) 
     205#            node.vector = min + numpy.random.rand(dimension) * (max - min) 
     206            node.vector = min + random.randint(0, dimension) * (max - min) 
    165207 
    166208    def initialize_map_linear(self, data, map_shape=(10, 20)): 
Note: See TracChangeset for help on using the changeset viewer.