Changeset 7477:9c5b056351ac in orange


Ignore:
Timestamp:
02/04/11 17:07:32 (3 years ago)
Author:
anze <anze.staric@…>
Branch:
default
Convert:
564d0ce0d9a08a1d84daa452a59aacb20f997ffc
Message:

Regression test for m-estimate

Location:
orange
Files:
1 added
1 deleted
2 edited

Legend:

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

    r7432 r7477  
    3030Examples 
    3131======== 
    32 Example (`bayes-run.py`_, uses `iris.tab`_) 
    33  
    34 .. literalinclude:: code/bayes-run.py 
     32NaiveLearner can estimate probabilities using relative frequencies or 
     33m-estimate. 
     34 
     35Example (`bayes-mestimate.py`_, uses `iris.tab`_) 
     36 
     37.. literalinclude:: code/bayes-mestimate.py 
    3538    :lines: 7- 
    36      
     39 
     40Observing probabilities shows a shift towards the third, more frequent class - 
     41as compared to probabilities above, where relative frequencies were used. 
     42Note that the change in error estimation did not have any effect on apriori 
     43probabilities. 
     44 
     45Example (`bayes-thresholdAdjustment.py`_, uses `adult-sample.tab`_) 
     46 
     47.. literalinclude:: code/bayes-thresholdAdjustment.py 
     48    :lines: 7- 
     49     
     50Setting adjustThreshold paramater can sometimes improve the results. :: 
     51 
     52    [0.7901746265516516, 0.8280138859667578] 
     53 
    3754Let us load the data, induce a classifier and see how it performs on the first 
    3855five examples. 
     
    158175 
    159176.. _bayes-run.py: code/bayes-run.py 
     177.. _bayes-thresholdAdjustment.py: code/bayes-thresholdAdjustment.py 
    160178.. _iris.tab: code/iris.tab 
    161179 
     
    340358            bayes.conditionalEstimatorConstructor = Orange.core.ConditionalProbabilityEstimatorConstructor_ByRows() 
    341359            bayes.conditionalEstimatorConstructor.estimatorConstructor=bayes.estimatorConstructor 
    342              
    343360        if self.conditionalEstimatorConstructorContinuous: 
    344361            bayes.conditionalEstimatorConstructorContinuous = self.conditionalEstimatorConstructorContinuous 
    345              
     362        if self.adjustThreshold: 
     363            bayes.adjustThreshold = self.adjustThreshold 
    346364        return NaiveClassifier(bayes(instances, weight)) 
    347365             
     
    406424        :param class_: class variable for which the probability should be 
    407425                outputed 
    408         :type class_: :class:Orange.data.Variable` 
     426        :type class_: :class:`Orange.data.Variable` 
    409427        :param instance: instance to be classified 
    410428        :type instance: :class:`Orange.data.Instance` 
  • orange/doc/Orange/rst/code/bayes-mestimate.py

    r7446 r7477  
    1 # Description: Naive Bayes Learner on iris data set 
     1# Description: Naive Bayes Learner with m-estimate 
    22# Category:    classification 
    33# Uses:        iris 
     
    66 
    77import Orange 
    8 table = Orange.data.Table("iris.tab") 
    98 
    10 learner = Orange.classification.bayes.NaiveLearner() 
    11 classifier = learner(table) 
     9table = Orange.data.Table("lenses.tab") 
    1210 
    13 for ex in table[:5]: 
    14     print ex.getclass(), classifier(ex) 
     11bayes_L = Orange.classification.bayes.NaiveLearner(name="Naive Bayes") 
     12bayesWithM_L = Orange.classification.bayes.NaiveLearner(m=2, name="Naive Bayes w/ m-estimate") 
     13bayes = bayes_L(table) 
     14bayesWithM = bayesWithM_L(table) 
     15 
     16print bayes.conditionalDistributions 
     17"""<<'pre-presbyopic': <0.625, 0.125, 0.250>, 'presbyopic': <0.750, 0.125, 0.125>, ...>>""" 
     18print bayesWithM.conditionalDistributions 
     19"""<<'pre-presbyopic': <0.625, 0.133, 0.242>, 'presbyopic': <0.725, 0.133, 0.142>, ...>>""" 
     20 
     21print bayes.distribution 
     22"""<0.625, 0.167, 0.208>""" 
     23print bayesWithM.distribution 
     24"""<0.625, 0.167, 0.208>""" 
Note: See TracChangeset for help on using the changeset viewer.