Changeset 7810:c3b31775ed2c in orange


Ignore:
Timestamp:
04/05/11 12:38:22 (3 years ago)
Author:
anze <anze.staric@…>
Branch:
default
Convert:
ca5ad246eee535b11a6c537c762cc77750d11a67
Message:

Added new example for NaiveLearner.

Location:
orange
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/classification/bayes.py

    r7617 r7810  
    5656    [0.7901746265516516, 0.8280138859667578] 
    5757 
     58Probabilities for continuous features are estimated with \ 
     59:class:`ProbabilityEstimatorConstructor_loess`. 
     60(`bayes-plot-iris.py`_, uses `iris.tab`_): 
     61 
     62.. literalinclude:: code/bayes-plot-iris.py 
     63    :lines: 4- 
     64     
     65.. image:: code/bayes-iris.png 
     66   :scale: 50 % 
     67 
     68If petal lengths are shorter, the most probable class is "setosa". Irises with 
     69middle petal lengths belong to "versicolor", while longer petal lengths indicate 
     70for "virginica". Critical values where the decision would change are at about 
     715.4 and 6.3. 
     72 
     73 
    5874.. _bayes-run.py: code/bayes-run.py 
    5975.. _bayes-thresholdAdjustment.py: code/bayes-thresholdAdjustment.py 
    6076.. _bayes-mestimate.py: code/bayes-mestimate.py 
     77.. _bayes-plot-iris.py: code/bayes-plot-iris.py 
    6178.. _adult-sample.tab: code/adult-sample.tab 
    6279.. _iris.tab: code/iris.tab 
     
    345362        return self.nativeBayesClassifier.p(class_, instance) 
    346363     
    347     def printModel(self): 
    348         """Print classifier in human friendly format.""" 
     364    def __str__(self): 
     365        """return classifier in human friendly format.""" 
    349366        nValues=len(self.classVar.values) 
    350367        frmtStr=' %10.3f'*nValues 
    351368        classes=" "*20+ ((' %10s'*nValues) % tuple([i[:10] for i in self.classVar.values])) 
    352         print classes 
    353         print "class probabilities "+(frmtStr % tuple(self.distribution)) 
    354         print 
    355      
    356         for i in self.conditionalDistributions: 
    357             print "Attribute", i.variable.name 
    358             print classes 
    359             for v in range(len(i.variable.values)): 
    360                 print ("%20s" % i.variable.values[v][:20]) + (frmtStr % tuple(i[v])) 
    361             print 
     369         
     370        return "\n".join( 
     371            classes, 
     372            "class probabilities "+(frmtStr % tuple(self.distribution)), 
     373            "", 
     374            "\n".join(["\n".join( 
     375                "Attribute " + i.variable.name, 
     376                classes, 
     377                "\n".join( 
     378                    ("%20s" % i.variable.values[v][:20]) + (frmtStr % tuple(i[v])) 
     379                    for v in xrange(len(i.variable.values))) 
     380                ) for i in self.conditionalDistributions])) 
    362381             
    363382 
    364 printModel = NaiveClassifier.printModel 
     383def printModel(model): 
     384    print NaiveClassifier(model) 
Note: See TracChangeset for help on using the changeset viewer.