Changeset 9638:eb3af38491f2 in orange


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")

Location:
docs/reference/rst/code
Files:
1 added
25 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/attributes.py

    r9372 r9638  
    11import Orange 
    2 data = Orange.data.Table("titanic.tab") 
    3 var = data.domain[0] 
     2titanic = Orange.data.Table("titanic.tab") 
     3var = titanic.domain[0] 
    44print var 
    55print "Attributes", var.attributes 
  • docs/reference/rst/code/bayes-mestimate.py

    r9372 r9638  
    77import Orange 
    88 
    9 table = Orange.data.Table("lenses.tab") 
     9lenses = Orange.data.Table("lenses.tab") 
    1010 
    1111bayes_L = Orange.classification.bayes.NaiveLearner(name="Naive Bayes") 
    1212bayesWithM_L = Orange.classification.bayes.NaiveLearner(m=2, name="Naive Bayes w/ m-estimate") 
    13 bayes = bayes_L(table) 
    14 bayesWithM = bayesWithM_L(table) 
     13bayes = bayes_L(lenses) 
     14bayesWithM = bayesWithM_L(lenses) 
    1515 
    1616print bayes.conditional_distributions 
  • docs/reference/rst/code/bayes-thresholdAdjustment.py

    r9372 r9638  
    99from Orange.evaluation import testing, scoring 
    1010 
    11 table = Orange.data.Table("adult_sample.tab") 
     11adult = Orange.data.Table("adult_sample.tab") 
    1212 
    1313nb = bayes.NaiveLearner(name="Naive Bayes") 
    1414adjusted_nb = bayes.NaiveLearner(adjust_threshold=True, name="Adjusted Naive Bayes") 
    1515 
    16 results = testing.cross_validation([nb, adjusted_nb], table) 
     16results = testing.cross_validation([nb, adjusted_nb], adult) 
    1717print scoring.CA(results) 
  • docs/reference/rst/code/correspondence1.py

    r9372 r9638  
    88import Orange.statistics.contingency as cont 
    99 
    10 data = Orange.data.Table("bridges") 
    11 cm = cont.VarVar("PURPOSE", "MATERIAL", data) 
     10bridges = Orange.data.Table("bridges") 
     11cm = cont.VarVar("PURPOSE", "MATERIAL", bridges) 
    1212ca = corr.CA(cm) 
    1313 
     
    1717         
    1818print "PURPOSE" 
    19 report(ca.column_factors(), data.domain["PURPOSE"].values) 
     19report(ca.column_factors(), bridges.domain["PURPOSE"].values) 
    2020print  
    2121 
    2222print "MATERIAL" 
    23 report(ca.row_factors(), data.domain["PURPOSE"].values) 
     23report(ca.row_factors(), bridges.domain["PURPOSE"].values) 
    2424print  
  • docs/reference/rst/code/data.io-read.weka.py

    r9372 r9638  
    66 
    77import Orange 
    8 table = Orange.data.io.loadARFF('iris.arff') 
    9 print table.attribute_load_status 
    10 print table.domain 
    11 print table.domain.attributes 
    12 print "\n".join(["\t".join([str(value) for value in row]) for row in table]) 
     8iris = Orange.data.io.loadARFF('iris.arff') 
     9print iris.attribute_load_status 
     10print iris.domain 
     11print iris.domain.attributes 
     12print "\n".join(["\t".join([str(value) for value in row]) for row in iris]) 
    1313print 
    1414 
    15 table = Orange.data.Table('iris.arff') 
    16 print table.attribute_load_status 
    17 print table.domain 
    18 print table.domain.attributes 
    19 print "\n".join(["\t".join([str(value) for value in row]) for row in table]) 
     15iris = Orange.data.Table('iris.arff') 
     16print iris.attribute_load_status 
     17print iris.domain 
     18print iris.domain.attributes 
     19print "\n".join(["\t".join([str(value) for value in row]) for row in iris]) 
  • docs/reference/rst/code/data.io-write.weka.py

    r9372 r9638  
    66 
    77import Orange 
    8 table = Orange.data.Table('iris.tab') 
    9 Orange.data.io.toARFF('iris.testsave.arff', table) 
    10 table.save('iris.testsave.arff') 
     8iris = Orange.data.Table('iris.tab') 
     9Orange.data.io.toARFF('iris.testsave.arff', iris) 
     10iris.save('iris.testsave.arff') 
    1111f = open('iris.testsave.arff') 
    1212for line in f: 
  • docs/reference/rst/code/distances-test.py

    r9372 r9638  
    22 
    33# Read some data 
    4 table = Orange.data.Table("iris.tab") 
     4iris = Orange.data.Table("iris.tab") 
    55 
    66# Euclidean distance constructor 
    77d2Constr = Orange.distance.instances.EuclideanConstructor() 
    8 d2 = d2Constr(table) 
     8d2 = d2Constr(iris) 
    99 
    1010# Constructs  
    11 dPears = Orange.distance.instances.PearsonRConstructor(table) 
     11dPears = Orange.distance.instances.PearsonRConstructor(iris) 
    1212 
    1313#reference instance 
    14 ref = table[0] 
     14ref = iris[0] 
    1515 
    1616print "Euclidean distances from the first data instance: " 
    1717 
    18 for ins in table[:5]: 
     18for ins in iris[:5]: 
    1919    print "%5.4f" % d2(ins, ref), 
    2020print  
     
    2222print "Pearson correlation distance from the first data instance: " 
    2323 
    24 for ins in table[:5]: 
     24for ins in iris[:5]: 
    2525    print "%5.4f" % dPears(ins, ref), 
    2626print  
  • docs/reference/rst/code/distributions-basic-stat.py

    r9372 r9638  
    11import Orange 
    22 
    3 myData = Orange.data.Table("iris.tab") 
    4 bas = Orange.statistics.basic.Domain(myData)  
     3iris = Orange.data.Table("iris.tab") 
     4bas = Orange.statistics.basic.Domain(iris)  
    55 
    66print "%20s %5s %5s %5s" % ("feature", "min", "max", "avg") 
  • docs/reference/rst/code/ensemble-forest-measure.py

    r9372 r9638  
    1212for fn in files: 
    1313    print "\nDATA:" + fn + "\n" 
    14     table = Orange.data.Table(fn) 
     14    iris = Orange.data.Table(fn) 
    1515 
    1616    measure = Orange.ensemble.forest.ScoreFeature(trees=100) 
    1717 
    1818    #call by attribute index 
    19     imp0 = measure(0, table)  
     19    imp0 = measure(0, iris)  
    2020    #call by orange.Variable 
    21     imp1 = measure(table.domain.attributes[1], table) 
     21    imp1 = measure(iris.domain.attributes[1], iris) 
    2222    print "first: %0.2f, second: %0.2f\n" % (imp0, imp1) 
    2323 
     
    2626            rand=random.Random(10)) 
    2727 
    28     imp0 = measure(0, table) 
    29     imp1 = measure(table.domain.attributes[1], table) 
     28    imp0 = measure(0, iris) 
     29    imp1 = measure(iris.domain.attributes[1], iris) 
    3030    print "first: %0.2f, second: %0.2f\n" % (imp0, imp1) 
    3131 
    3232    print "All importances:" 
    33     for at in table.domain.attributes: 
    34         print "%15s: %6.2f" % (at.name, measure(at, table)) 
     33    for at in iris.domain.attributes: 
     34        print "%15s: %6.2f" % (at.name, measure(at, iris)) 
  • docs/reference/rst/code/ensemble-forest.py

    r9372 r9638  
    1313 
    1414print "Classification: bupa.tab" 
    15 table = Orange.data.Table("bupa.tab") 
    16 results = Orange.evaluation.testing.cross_validation(learners, table, folds=3) 
     15bupa = Orange.data.Table("bupa.tab") 
     16results = Orange.evaluation.testing.cross_validation(learners, bupa, folds=3) 
    1717print "Learner  CA     Brier  AUC" 
    1818for i in range(len(learners)): 
     
    2323 
    2424print "Regression: housing.tab" 
    25 table = Orange.data.Table("housing.tab") 
    26 results = Orange.evaluation.testing.cross_validation(learners, table, folds=3) 
     25bupa = Orange.data.Table("housing.tab") 
     26results = Orange.evaluation.testing.cross_validation(learners, bupa, folds=3) 
    2727print "Learner  MSE    RSE    R2" 
    2828for i in range(len(learners)): 
  • docs/reference/rst/code/ensemble-forest2.py

    r9372 r9638  
    77import Orange 
    88 
    9 table = Orange.data.Table('bupa.tab') 
     9bupa = Orange.data.Table('bupa.tab') 
    1010 
    1111tree = Orange.classification.tree.TreeLearner() 
     
    1414 
    1515forest_learner = Orange.ensemble.forest.RandomForestLearner(base_learner=tree, trees=50, attributes=3) 
    16 forest = forest_learner(table) 
     16forest = forest_learner(bupa) 
    1717 
    1818for c in forest.classifiers: 
  • docs/reference/rst/code/ensemble.py

    r9372 r9638  
    1111bg = Orange.ensemble.bagging.BaggedLearner(tree, name="bagged tree") 
    1212 
    13 table = Orange.data.Table("lymphography.tab") 
     13lymphography = Orange.data.Table("lymphography.tab") 
    1414 
    1515learners = [tree, bs, bg] 
    16 results = Orange.evaluation.testing.cross_validation(learners, table, folds=3) 
     16results = Orange.evaluation.testing.cross_validation(learners, lymphography, folds=3) 
    1717print "Classification Accuracy:" 
    1818for i in range(len(learners)): 
  • 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 
  • docs/reference/rst/code/imputation-minimal-imputer.py

    r9372 r9638  
    1111       imputer_constructor=Orange.feature.imputation.ImputerConstructor_minimal) 
    1212 
    13 table = Orange.data.Table("voting") 
    14 res = Orange.evaluation.testing.cross_validation([ba, imba], table) 
     13voting = Orange.data.Table("voting") 
     14res = Orange.evaluation.testing.cross_validation([ba, imba], voting) 
    1515CAs = Orange.evaluation.scoring.CA(res) 
    1616 
  • docs/reference/rst/code/instance-construct.py

    r9372 r9638  
    11import Orange 
    2 data = Orange.data.Table("lenses") 
    3 domain = data.domain 
     2lenses = Orange.data.Table("lenses") 
     3domain = lenses.domain 
    44inst = Orange.data.Instance(domain, ["young", "myope", 
    55                               "yes", "reduced", "soft"]) 
  • docs/reference/rst/code/instance-metavar.py

    r9525 r9638  
    11import random 
    22import Orange 
    3 data = Orange.data.Table("lenses") 
     3lenses = Orange.data.Table("lenses") 
    44id = Orange.data.new_meta_id() 
    5 for inst in data: 
     5for inst in lenses: 
    66    inst[id] = random.random() 
    7 print data[0] 
     7print lenses[0] 
  • docs/reference/rst/code/kmeans-run-callback.py

    r9372 r9638  
    44    print "Iteration: %d, changes: %d, score: %.4f" % (km.iteration, km.nchanges, km.score) 
    55     
    6 table = Orange.data.Table("iris") 
    7 km = Orange.clustering.kmeans.Clustering(table, 3, minscorechange=0, inner_callback=callback) 
     6iris = Orange.data.Table("iris") 
     7km = Orange.clustering.kmeans.Clustering(iris, 3, minscorechange=0, inner_callback=callback) 
  • docs/reference/rst/code/kmeans-run.py

    r9372 r9638  
    11import Orange 
    22     
    3 table = Orange.data.Table("iris") 
    4 km = Orange.clustering.kmeans.Clustering(table, 3) 
     3iris = Orange.data.Table("iris") 
     4km = Orange.clustering.kmeans.Clustering(iris, 3) 
    55print km.clusters[-10:] 
  • docs/reference/rst/code/kmeans-silhouette.py

    r9372 r9638  
    11import Orange 
    22 
    3 table = Orange.data.Table("voting") 
     3voting = Orange.data.Table("voting") 
    44# table = Orange.data.Table("iris") 
    55 
    66for k in range(2, 8): 
    7     km = Orange.clustering.kmeans.Clustering(table, k, initialization=Orange.clustering.kmeans.init_diversity) 
     7    km = Orange.clustering.kmeans.Clustering(voting, k, initialization=Orange.clustering.kmeans.init_diversity) 
    88    score = Orange.clustering.kmeans.score_silhouette(km) 
    99    print k, score 
    1010 
    11 km = Orange.clustering.kmeans.Clustering(table, 3, initialization=Orange.clustering.kmeans.init_diversity) 
     11km = Orange.clustering.kmeans.Clustering(voting, 3, initialization=Orange.clustering.kmeans.init_diversity) 
    1212Orange.clustering.kmeans.plot_silhouette(km, "kmeans-silhouette.png") 
  • docs/reference/rst/code/knnExample0.py

    r9372 r9638  
    11import Orange 
    2 table = Orange.data.Table("iris") 
     2iris = Orange.data.Table("iris") 
    33 
    44knnLearner = Orange.classification.knn.kNNLearner() 
    55knnLearner.k = 10 
    6 knnClassifier = knnLearner(table) 
     6knnClassifier = knnLearner(iris) 
  • docs/reference/rst/code/knnExample1.py

    r9372 r9638  
    11import Orange 
    2 table = Orange.data.Table("iris") 
     2iris = Orange.data.Table("iris") 
    33 
    4 rndind = Orange.core.MakeRandomIndices2(table, p0=0.8) 
    5 train = table.select(rndind, 0) 
    6 test = table.select(rndind, 1) 
     4rndind = Orange.core.MakeRandomIndices2(iris, p0=0.8) 
     5train = iris.select(rndind, 0) 
     6test = iris.select(rndind, 1) 
    77 
    88knn = Orange.classification.knn.kNNLearner(train, k=10) 
  • docs/reference/rst/code/knnExample2.py

    r9372 r9638  
    11import Orange 
    2 table = Orange.data.Table("iris") 
     2iris = Orange.data.Table("iris") 
    33 
    44knn = Orange.classification.knn.kNNLearner() 
    55knn.k = 10 
    66knn.distance_constructor = Orange.core.ExamplesDistanceConstructor_Hamming() 
    7 knn = knn(table) 
     7knn = knn(iris) 
    88for i in range(5): 
    9     instance = table.randomexample() 
     9    instance = iris.randomexample() 
    1010    print instance.getclass(), knn(instance) 
  • docs/reference/rst/code/knnInstanceDistance.py

    r9525 r9638  
    11import Orange 
    22 
    3 table = Orange.data.Table("lenses") 
     3lenses = Orange.data.Table("lenses") 
    44 
    55nnc = Orange.classification.knn.FindNearestConstructor() 
     
    77 
    88did = Orange.data.new_meta_id() 
    9 nn = nnc(table, 0, did) 
     9nn = nnc(lenses, 0, did) 
    1010 
    11 print "*** Reference instance: ", table[0] 
    12 for inst in nn(table[0], 5): 
     11print "*** Reference instance: ", lenses[0] 
     12for inst in nn(lenses[0], 5): 
    1313    print inst 
  • docs/reference/rst/code/knnlearner.py

    r9372 r9638  
    66 
    77import Orange 
    8 table = Orange.data.Table("iris") 
     8iris = Orange.data.Table("iris") 
    99 
    1010print "Testing using euclidean distance" 
    11 rndind = Orange.core.MakeRandomIndices2(table, p0=0.8) 
    12 train = table.select(rndind, 0) 
    13 test = table.select(rndind, 1) 
     11rndind = Orange.core.MakeRandomIndices2(iris, p0=0.8) 
     12train = iris.select(rndind, 0) 
     13test = iris.select(rndind, 1) 
    1414 
    1515knn = Orange.classification.knn.kNNLearner(train, k=10) 
     
    2020print "\n" 
    2121print "Testing using hamming distance" 
    22 table = Orange.data.Table("iris") 
     22iris = Orange.data.Table("iris") 
    2323knn = Orange.classification.knn.kNNLearner() 
    2424knn.k = 10 
  • docs/reference/rst/code/logreg-run.py

    r9372 r9638  
    1 from Orange import * 
     1import Orange 
    22 
    3 table = data.Table("titanic") 
    4 lr = classification.logreg.LogRegLearner(table) 
     3titanic = Orange.data.Table("titanic") 
     4lr = Orange.classification.logreg.LogRegLearner(titanic) 
    55 
    66# compute classification accuracy 
    77correct = 0.0 
    8 for ex in table: 
     8for ex in titanic: 
    99    if lr(ex) == ex.getclass(): 
    1010        correct += 1 
    11 print "Classification accuracy:", correct / len(table) 
    12 classification.logreg.dump(lr) 
     11print "Classification accuracy:", correct / len(titanic) 
     12Orange.classification.logreg.dump(lr) 
Note: See TracChangeset for help on using the changeset viewer.