Ignore:
Timestamp:
02/05/12 22:37:07 (2 years ago)
Author:
umek@…
Branch:
default
rebase_source:
eb6a120705f3462186b982a698c0a7ad9f947e24
Message:

Changed table to data or name of the data set.

For example - instead of

table = Orange.data.Table("housing")

is changed to

housing = Orange.data.Table("housing")

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/imputation-complex.py

    r9372 r9638  
    77import Orange 
    88 
    9 table = Orange.data.Table("bridges") 
     9bridges = Orange.data.Table("bridges") 
    1010 
    1111print "*** IMPUTING MINIMAL VALUES ***" 
    12 imputer = Orange.feature.imputation.ImputerConstructor_minimal(table) 
     12imputer = Orange.feature.imputation.ImputerConstructor_minimal(bridges) 
    1313print "Example w/ missing values" 
    14 print table[19] 
     14print bridges[19] 
    1515print "Imputed:" 
    16 print imputer(table[19]) 
     16print imputer(bridges[19]) 
    1717print 
    1818 
    19 impdata = imputer(table) 
     19impdata = imputer(bridges) 
    2020for i in range(20, 25): 
    21     print table[i] 
     21    print bridges[i] 
    2222    print impdata[i] 
    2323    print 
     
    2525 
    2626print "*** IMPUTING MAXIMAL VALUES ***" 
    27 imputer = Orange.feature.imputation.ImputerConstructor_maximal(table) 
     27imputer = Orange.feature.imputation.ImputerConstructor_maximal(bridges) 
    2828print "Example w/ missing values" 
    29 print table[19] 
     29print bridges[19] 
    3030print "Imputed:" 
    31 print imputer(table[19]) 
     31print imputer(bridges[19]) 
    3232print 
    3333 
    34 impdata = imputer(table) 
     34impdata = imputer(bridges) 
    3535for i in range(20, 25): 
    36     print table[i] 
     36    print bridges[i] 
    3737    print impdata[i] 
    3838    print 
     
    4040 
    4141print "*** IMPUTING AVERAGE/MAJORITY VALUES ***" 
    42 imputer = Orange.feature.imputation.ImputerConstructor_average(table) 
     42imputer = Orange.feature.imputation.ImputerConstructor_average(bridges) 
    4343print "Example w/ missing values" 
    44 print table[19] 
     44print bridges[19] 
    4545print "Imputed:" 
    46 print imputer(table[19]) 
     46print imputer(bridges[19]) 
    4747print 
    4848 
    49 impdata = imputer(table) 
     49impdata = imputer(bridges) 
    5050for i in range(20, 25): 
    51     print table[i] 
     51    print bridges[i] 
    5252    print impdata[i] 
    5353    print 
     
    5555 
    5656print "*** MANUALLY CONSTRUCTED IMPUTER ***" 
    57 imputer = Orange.feature.imputation.Imputer_defaults(table.domain) 
     57imputer = Orange.feature.imputation.Imputer_defaults(bridges.domain) 
    5858imputer.defaults["LENGTH"] = 1234 
    5959print "Example w/ missing values" 
    60 print table[19] 
     60print bridges[19] 
    6161print "Imputed:" 
    62 print imputer(table[19]) 
     62print imputer(bridges[19]) 
    6363print 
    6464 
    65 impdata = imputer(table) 
     65impdata = imputer(bridges) 
    6666for i in range(20, 25): 
    67     print table[i] 
     67    print bridges[i] 
    6868    print impdata[i] 
    6969    print 
     
    7474imputer = Orange.feature.imputation.ImputerConstructor_model() 
    7575imputer.learner_continuous = imputer.learner_discrete = Orange.classification.tree.TreeLearner(minSubset=20) 
    76 imputer = imputer(table) 
     76imputer = imputer(bridges) 
    7777print "Example w/ missing values" 
    78 print table[19] 
     78print bridges[19] 
    7979print "Imputed:" 
    80 print imputer(table[19]) 
     80print imputer(bridges[19]) 
    8181print 
    8282 
    83 impdata = imputer(table) 
     83impdata = imputer(bridges) 
    8484for i in range(20, 25): 
    85     print table[i] 
     85    print bridges[i] 
    8686    print impdata[i] 
    8787    print 
     
    9292imputer.learner_continuous = Orange.regression.mean.MeanLearner() 
    9393imputer.learner_discrete = Orange.classification.bayes.NaiveLearner() 
    94 imputer = imputer(table) 
     94imputer = imputer(bridges) 
    9595print "Example w/ missing values" 
    96 print table[19] 
     96print bridges[19] 
    9797print "Imputed:" 
    98 print imputer(table[19]) 
     98print imputer(bridges[19]) 
    9999print 
    100 impdata = imputer(table) 
     100impdata = imputer(bridges) 
    101101for i in range(20, 25): 
    102     print table[i] 
     102    print bridges[i] 
    103103    print impdata[i] 
    104104    print 
     
    107107print "*** CUSTOM IMPUTATION BY MODELS ***" 
    108108imputer = Orange.feature.imputation.Imputer_model() 
    109 imputer.models = [None] * len(table.domain) 
    110 imputer.models[table.domain.index("LANES")] = Orange.classification.ConstantClassifier(2.0) 
    111 tord = Orange.classification.ConstantClassifier(Orange.data.Value(table.domain["T-OR-D"], "THROUGH")) 
    112 imputer.models[table.domain.index("T-OR-D")] = tord 
     109imputer.models = [None] * len(bridges.domain) 
     110imputer.models[bridges.domain.index("LANES")] = Orange.classification.ConstantClassifier(2.0) 
     111tord = Orange.classification.ConstantClassifier(Orange.data.Value(bridges.domain["T-OR-D"], "THROUGH")) 
     112imputer.models[bridges.domain.index("T-OR-D")] = tord 
    113113 
    114114 
    115 len_domain = Orange.data.Domain(["MATERIAL", "SPAN", "ERECTED", "LENGTH"], table.domain) 
    116 len_data = Orange.data.Table(len_domain, table) 
     115len_domain = Orange.data.Domain(["MATERIAL", "SPAN", "ERECTED", "LENGTH"], bridges.domain) 
     116len_data = Orange.data.Table(len_domain, bridges) 
    117117len_tree = Orange.classification.tree.TreeLearner(len_data, minSubset=20) 
    118 imputer.models[table.domain.index("LENGTH")] = len_tree 
     118imputer.models[bridges.domain.index("LENGTH")] = len_tree 
    119119print len_tree 
    120120 
    121 span_var = table.domain["SPAN"] 
     121span_var = bridges.domain["SPAN"] 
    122122def compute_span(ex, rw): 
    123123    if ex["TYPE"] == "WOOD" or ex["PURPOSE"] == "WALK": 
     
    126126        return orange.Value(span_var, "MEDIUM") 
    127127 
    128 imputer.models[table.domain.index("SPAN")] = compute_span 
     128imputer.models[bridges.domain.index("SPAN")] = compute_span 
    129129 
    130130for i in range(20, 25): 
    131     print table[i] 
     131    print bridges[i] 
    132132    print impdata[i] 
    133133    print 
     
    135135 
    136136print "*** IMPUTATION WITH SPECIAL VALUES ***" 
    137 imputer = Orange.feature.imputation.ImputerConstructor_asValue(table) 
    138 original = table[19] 
    139 imputed = imputer(table[19]) 
     137imputer = Orange.feature.imputation.ImputerConstructor_asValue(bridges) 
     138original = bridges[19] 
     139imputed = imputer(bridges[19]) 
    140140print original.domain 
    141141print 
     
    151151print 
    152152 
    153 impdata = imputer(table) 
     153impdata = imputer(bridges) 
    154154for i in range(20, 25): 
    155     print table[i] 
     155    print bridges[i] 
    156156    print impdata[i] 
    157157    print 
Note: See TracChangeset for help on using the changeset viewer.