Ignore:
Timestamp:
02/06/12 20:01:02 (2 years ago)
Author:
lanumek
Branch:
default
Children:
9835:e48466fc6eb2, 9841:05a160804431
rebase_source:
8cf30121654f25c9cb6d8ac9bdaf163e305d62da
Message:

Changed names of data sets (table replaced with data or name of the data set).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/scoring-info-lenses.py

    r9525 r9823  
    77import Orange, random 
    88 
    9 table = Orange.data.Table("lenses") 
     9lenses = Orange.data.Table("lenses") 
    1010 
    1111meas = Orange.feature.scoring.InfoGain() 
    1212 
    13 astigm = table.domain["astigmatic"] 
    14 print "Information gain of 'astigmatic': %6.4f" % meas(astigm, table) 
     13astigm = lenses.domain["astigmatic"] 
     14print "Information gain of 'astigmatic': %6.4f" % meas(astigm, lenses) 
    1515 
    16 classdistr = Orange.statistics.distribution.Distribution(table.domain.class_var, table) 
    17 cont = Orange.statistics.contingency.VarClass("tear_rate", table) 
     16classdistr = Orange.statistics.distribution.Distribution(lenses.domain.class_var, lenses) 
     17cont = Orange.statistics.contingency.VarClass("tear_rate", lenses) 
    1818print "Information gain of 'tear_rate': %6.4f" % meas(cont, classdistr) 
    1919 
    20 dcont = Orange.statistics.contingency.Domain(table) 
     20dcont = Orange.statistics.contingency.Domain(lenses) 
    2121print "Information gain of the first attribute: %6.4f" % meas(0, dcont) 
    2222print 
     
    2424print "*** A set of more exhaustive tests for different way of passing arguments to MeasureAttribute ***" 
    2525 
    26 names = [a.name for a in table.domain.attributes] 
     26names = [a.name for a in lenses.domain.attributes] 
    2727attrs = len(names) 
    2828 
     
    3333 
    3434print "Computing information gain directly from examples" 
    35 print fstr % (("- by attribute number:",) + tuple([meas(i, table) for i in range(attrs)])) 
    36 print fstr % (("- by attribute name:",) + tuple([meas(i, table) for i in names])) 
    37 print fstr % (("- by attribute descriptor:",) + tuple([meas(i, table) for i in table.domain.attributes])) 
     35print fstr % (("- by attribute number:",) + tuple([meas(i, lenses) for i in range(attrs)])) 
     36print fstr % (("- by attribute name:",) + tuple([meas(i, lenses) for i in names])) 
     37print fstr % (("- by attribute descriptor:",) + tuple([meas(i, lenses) for i in lenses.domain.attributes])) 
    3838print 
    3939 
    40 dcont = Orange.statistics.contingency.Domain(table) 
     40dcont = Orange.statistics.contingency.Domain(lenses) 
    4141print "Computing information gain from DomainContingency" 
    4242print fstr % (("- by attribute number:",) + tuple([meas(i, dcont) for i in range(attrs)])) 
    4343print fstr % (("- by attribute name:",) + tuple([meas(i, dcont) for i in names])) 
    44 print fstr % (("- by attribute descriptor:",) + tuple([meas(i, dcont) for i in table.domain.attributes])) 
     44print fstr % (("- by attribute descriptor:",) + tuple([meas(i, dcont) for i in lenses.domain.attributes])) 
    4545print 
    4646 
    4747print "Computing information gain from DomainContingency" 
    48 cdist = Orange.statistics.distribution.Distribution(table.domain.class_var, table) 
    49 print fstr % (("- by attribute number:",) + tuple([meas(Orange.statistics.contingency.VarClass(i, table), cdist) for i in range(attrs)])) 
    50 print fstr % (("- by attribute name:",) + tuple([meas(Orange.statistics.contingency.VarClass(i, table), cdist) for i in names])) 
    51 print fstr % (("- by attribute descriptor:",) + tuple([meas(Orange.statistics.contingency.VarClass(i, table), cdist) for i in table.domain.attributes])) 
     48cdist = Orange.statistics.distribution.Distribution(lenses.domain.class_var, lenses) 
     49print fstr % (("- by attribute number:",) + tuple([meas(Orange.statistics.contingency.VarClass(i, lenses), cdist) for i in range(attrs)])) 
     50print fstr % (("- by attribute name:",) + tuple([meas(Orange.statistics.contingency.VarClass(i, lenses), cdist) for i in names])) 
     51print fstr % (("- by attribute descriptor:",) + tuple([meas(Orange.statistics.contingency.VarClass(i, lenses), cdist) for i in lenses.domain.attributes])) 
    5252print 
    5353 
    54 values = ["v%i" % i for i in range(len(table.domain[2].values)*len(table.domain[3].values))] 
     54values = ["v%i" % i for i in range(len(lenses.domain[2].values)*len(lenses.domain[3].values))] 
    5555cartesian = Orange.data.variable.Discrete("cart", values = values) 
    56 cartesian.get_value_from = Orange.classification.lookup.ClassifierByLookupTable(cartesian, table.domain[2], table.domain[3], values) 
     56cartesian.get_value_from = Orange.classification.lookup.ClassifierByLookupTable(cartesian, lenses.domain[2], lenses.domain[3], values) 
    5757 
    58 print "Information gain of Cartesian product of %s and %s: %6.4f" % (table.domain[2].name, table.domain[3].name, meas(cartesian, table)) 
     58print "Information gain of Cartesian product of %s and %s: %6.4f" % (lenses.domain[2].name, lenses.domain[3].name, meas(cartesian, lenses)) 
    5959 
    6060mid = Orange.data.new_meta_id() 
    61 table.domain.add_meta(mid, Orange.data.variable.Discrete(values = ["v0", "v1"])) 
    62 table.add_meta_attribute(mid) 
     61lenses.domain.add_meta(mid, Orange.data.variable.Discrete(values = ["v0", "v1"])) 
     62lenses.add_meta_attribute(mid) 
    6363 
    6464rg = random.Random() 
    6565rg.seed(0) 
    66 for ex in table: 
     66for ex in lenses: 
    6767    ex[mid] = Orange.data.Value(rg.randint(0, 1)) 
    6868 
    69 print "Information gain for a random meta attribute: %6.4f" % meas(mid, table) 
     69print "Information gain for a random meta attribute: %6.4f" % meas(mid, lenses) 
Note: See TracChangeset for help on using the changeset viewer.