Changeset 9823:7f9c3f3c6474 in orange


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

Location:
docs/reference/rst/code
Files:
70 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/distances-test.py

    r9724 r9823  
    55 
    66# Euclidean distance constructor 
    7 d2Constr = Orange.distance.Euclidean() 
     7d2Constr = Orange.distance.instances.EuclideanConstructor() 
    88d2 = d2Constr(iris) 
    99 
    1010# Constructs  
    11 dPears = Orange.distance.PearsonR(iris) 
     11dPears = Orange.distance.instances.PearsonRConstructor(iris) 
    1212 
    1313#reference instance 
  • docs/reference/rst/code/ensemble-forest.py

    r9734 r9823  
    88 
    99forest = Orange.ensemble.forest.RandomForestLearner(trees=50, name="forest") 
    10 tree = Orange.classification.tree.TreeLearner(min_examples=2, m_prunning=2, \ 
    11                             same_majority_pruning=True, name='tree') 
     10tree = Orange.classification.tree.TreeLearner(minExamples=2, mForPrunning=2, \ 
     11                            sameMajorityPruning=True, name='tree') 
    1212learners = [tree, forest] 
    1313 
  • docs/reference/rst/code/knnExample2.py

    r9724 r9823  
    44knn = Orange.classification.knn.kNNLearner() 
    55knn.k = 10 
    6 knn.distance_constructor = Orange.distance.Hamming() 
     6knn.distance_constructor = Orange.core.ExamplesDistanceConstructor_Hamming() 
    77knn = knn(iris) 
    88for i in range(5): 
  • docs/reference/rst/code/knnInstanceDistance.py

    r9724 r9823  
    44 
    55nnc = Orange.classification.knn.FindNearestConstructor() 
    6 nnc.distanceConstructor = Orange.distance.Euclidean() 
     6nnc.distanceConstructor = Orange.core.ExamplesDistanceConstructor_Euclidean() 
    77 
    88did = Orange.data.new_meta_id() 
  • docs/reference/rst/code/knnlearner.py

    r9724 r9823  
    1515knn = Orange.classification.knn.kNNLearner(train, k=10) 
    1616for i in range(5): 
    17     instance = test.random_instance() 
     17    instance = test.randomexample() 
    1818    print instance.getclass(), knn(instance) 
    1919 
     
    2323knn = Orange.classification.knn.kNNLearner() 
    2424knn.k = 10 
    25 knn.distance_constructor = Orange.distance.Hamming() 
     25knn.distanceConstructor = Orange.core.ExamplesDistanceConstructor_Hamming() 
    2626knn = knn(train) 
    2727for i in range(5): 
    28     instance = test.random_instance() 
     28    instance = test.randomexample() 
    2929    print instance.getclass(), knn(instance) 
  • docs/reference/rst/code/logreg-singularities.py

    r9818 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("adult_sample") 
    4 lr = Orange.classification.logreg.LogRegLearner(table, remove_singular=1) 
     3adult = Orange.data.Table("adult_sample") 
     4lr = Orange.classification.logreg.LogRegLearner(adult, removeSingular=1) 
    55 
    6 for ex in table[:5]: 
     6for ex in adult[:5]: 
    77    print ex.getclass(), lr(ex) 
    88Orange.classification.logreg.dump(lr) 
  • docs/reference/rst/code/lookup-lookup.py

    r9372 r9823  
    77import Orange 
    88 
    9 table = Orange.data.Table("monks-1") 
     9monks = Orange.data.Table("monks-1") 
    1010 
    11 a, b, e = table.domain["a"], table.domain["b"], table.domain["e"] 
     11a, b, e = monks.domain["a"], monks.domain["b"], monks.domain["e"] 
    1212 
    1313ab = Orange.data.variable.Discrete("a==b", values = ["no", "yes"]) 
     
    1919                    ["yes", "no", "no", "no", "?"]) 
    2020 
    21 table2 = table.select([a, b, ab, e, e1, table.domain.class_var]) 
     21monks2 = monks.select([a, b, ab, e, e1, monks.domain.class_var]) 
    2222 
    2323for i in range(5): 
    24     print table2.random_example() 
     24    print monks2.random_example() 
    2525 
    2626for i in range(5): 
    27     ex = table.random_example() 
     27    ex = monks.random_example() 
    2828    print "%s: ab %i, e1 %i " % (ex, ab.get_value_from.get_index(ex), 
    2929                                 e1.get_value_from.get_index(ex)) 
  • docs/reference/rst/code/majority-classification.py

    r9372 r9823  
    77import Orange 
    88 
    9 table = Orange.data.Table("monks-1") 
     9monks = Orange.data.Table("monks-1") 
    1010 
    1111treeLearner = Orange.classification.tree.TreeLearner() 
     
    1414learners = [treeLearner, bayesLearner, majorityLearner] 
    1515 
    16 res = Orange.evaluation.testing.cross_validation(learners, table) 
     16res = Orange.evaluation.testing.cross_validation(learners, monks) 
    1717CAs = Orange.evaluation.scoring.CA(res, reportSE=True) 
    1818 
  • docs/reference/rst/code/mds-advanced.py

    r9724 r9823  
    99 
    1010# Load some data 
    11 table = Orange.data.Table("iris.tab") 
     11iris = Orange.data.Table("iris.tab") 
    1212 
    1313# Construct a distance matrix using Euclidean distance 
    14 dist = Orange.distance.Euclidean(table) 
    15 matrix = Orange.core.SymMatrix(len(table)) 
    16 for i in range(len(table)): 
     14dist = Orange.core.ExamplesDistanceConstructor_Euclidean(iris) 
     15matrix = Orange.core.SymMatrix(len(iris)) 
     16for i in range(len(iris)): 
    1717   for j in range(i+1): 
    18        matrix[i, j] = dist(table[i], table[j]) 
     18       matrix[i, j] = dist(iris[i], iris[j]) 
    1919 
    2020# Run the Torgerson approximation and calculate stress 
     
    3434 
    3535# Print the points out 
    36 for (p, e) in zip(mds.points, table): 
     36for (p, e) in zip(mds.points, iris): 
    3737    print p, e 
  • docs/reference/rst/code/mds-euclid-torgerson-3d.py

    r9724 r9823  
    88 
    99# Load some data 
    10 table = Orange.data.Table("iris.tab") 
     10iris = Orange.data.Table("iris.tab") 
    1111 
    1212# Construct a distance matrix using Euclidean distance 
    13 dist = Orange.distance.Euclidean(table) 
    14 matrix = Orange.core.SymMatrix(len(table)) 
    15 matrix.setattr('items', table) 
    16 for i in range(len(table)): 
     13dist = Orange.distance.instances.EuclideanConstructor(iris) 
     14matrix = Orange.core.SymMatrix(len(iris)) 
     15matrix.setattr('items', iris) 
     16for i in range(len(iris)): 
    1717    for j in range(i+1): 
    18         matrix[i, j] = dist(table[i], table[j]) 
     18        matrix[i, j] = dist(iris[i], iris[j]) 
    1919 
    2020# Run the MDS 
  • docs/reference/rst/code/mds-scatterplot.py

    r9663 r9823  
    88 
    99# Load some data 
    10 table = Orange.data.Table("iris.tab") 
     10iris = Orange.data.Table("iris.tab") 
    1111 
    1212# Construct a distance matrix using Euclidean distance 
    13 euclidean = Orange.distance.EuclideanConstructor(table) 
    14 distance = Orange.core.SymMatrix(len(table)) 
    15 for i in range(len(table)): 
     13euclidean = Orange.distance.instances.EuclideanConstructor(iris) 
     14distance = Orange.core.SymMatrix(len(iris)) 
     15for i in range(len(iris)): 
    1616   for j in range(i+1): 
    17        distance[i, j] = euclidean(table[i], table[j]) 
     17       distance[i, j] = euclidean(iris[i], iris[j]) 
    1818 
    1919# Run 100 steps of MDS optimization 
     
    2727# Construct points (x, y, instanceClass) 
    2828points = [] 
    29 for (i, d) in enumerate(table): 
     29for (i, d) in enumerate(iris): 
    3030   points.append((mds.points[i][0], mds.points[i][1], d.getclass())) 
    3131 
    3232# Paint each class separately 
    33 for c in range(len(table.domain.class_var.values)): 
     33for c in range(len(iris.domain.class_var.values)): 
    3434    sel = filter(lambda x: x[-1] == c, points) 
    3535    x = [s[0] for s in sel] 
  • docs/reference/rst/code/mean-regression.py

    r9372 r9823  
    77import Orange 
    88 
    9 table = Orange.data.Table("housing") 
     9housing = Orange.data.Table("housing") 
    1010 
    1111treeLearner = Orange.classification.tree.TreeLearner() #Orange.regression.TreeLearner() 
     
    1313learners = [treeLearner, meanLearner] 
    1414 
    15 res = Orange.evaluation.testing.cross_validation(learners, table) 
     15res = Orange.evaluation.testing.cross_validation(learners, housing) 
    1616MSEs = Orange.evaluation.scoring.MSE(res) 
    1717 
  • docs/reference/rst/code/misc-selection-bestonthefly.py

    r9372 r9823  
    77import Orange 
    88 
    9 table = Orange.data.Table("lymphography") 
     9lymphography = Orange.data.Table("lymphography") 
    1010 
    1111find_best = Orange.misc.selection.BestOnTheFly(call_compare_on_1st = True) 
    1212 
    13 for attr in table.domain.attributes: 
    14     find_best.candidate((Orange.feature.scoring.GainRatio(attr, table), attr)) 
     13for attr in lymphography.domain.attributes: 
     14    find_best.candidate((Orange.feature.scoring.GainRatio(attr, lymphography), attr)) 
    1515 
    1616print "%5.3f: %s" % find_best.winner() 
     
    1818find_best = Orange.misc.selection.BestOnTheFly(Orange.misc.selection.compare_first_bigger) 
    1919 
    20 for attr in table.domain.attributes: 
    21     find_best.candidate((Orange.feature.scoring.GainRatio(attr, table), attr)) 
     20for attr in lymphography.domain.attributes: 
     21    find_best.candidate((Orange.feature.scoring.GainRatio(attr, lymphography), attr)) 
    2222 
    2323print "%5.3f: %s" % find_best.winner() 
     
    2525find_best = Orange.misc.selection.BestOnTheFly() 
    2626 
    27 for attr in table.domain.attributes: 
    28     find_best.candidate(Orange.feature.scoring.GainRatio(attr, table)) 
     27for attr in lymphography.domain.attributes: 
     28    find_best.candidate(Orange.feature.scoring.GainRatio(attr, lymphography)) 
    2929 
    3030best_index = find_best.winner_index() 
    31 print "%5.3f: %s" % (find_best.winner(), table.domain[best_index]) 
     31print "%5.3f: %s" % (find_best.winner(), lymphography.domain[best_index]) 
  • docs/reference/rst/code/mlc-classify.py

    r9505 r9823  
    44import Orange 
    55 
    6 data = Orange.data.Table('emotions') 
     6emotions = Orange.data.Table('emotions') 
    77learner = Orange.multilabel.BRkNNLearner(k=5) 
    8 classifier = learner(data) 
    9 print classifier(data[0]) 
     8classifier = learner(emotions) 
     9print classifier(emotions[0]) 
    1010 
    1111learner = Orange.multilabel.MLkNNLearner(k=5) 
    12 classifier = learner(data) 
    13 print classifier(data[0]) 
     12classifier = learner(emotions) 
     13print classifier(emotions[0]) 
    1414 
    1515learner = Orange.multilabel.BinaryRelevanceLearner() 
    16 classifier = learner(data) 
    17 print classifier(data[0]) 
     16classifier = learner(emotions) 
     17print classifier(emotions[0]) 
    1818 
    1919learner = Orange.multilabel.LabelPowersetLearner() 
    20 classifier = learner(data) 
    21 print classifier(data[0]) 
     20classifier = learner(emotions) 
     21print classifier(emotions[0]) 
    2222 
    2323def test_mlc(data, learners): 
  • docs/reference/rst/code/mlc-evaluate.py

    r9505 r9823  
    1313 
    1414learners = [Orange.multilabel.MLkNNLearner(k=5)] 
    15 data = Orange.data.Table("emotions.tab") 
     15emotions = Orange.data.Table("emotions.tab") 
    1616 
    17 res = Orange.evaluation.testing.cross_validation(learners, data) 
     17res = Orange.evaluation.testing.cross_validation(learners, emotions) 
    1818print_results(res) 
    1919 
    20 res = Orange.evaluation.testing.leave_one_out(learners, data) 
     20res = Orange.evaluation.testing.leave_one_out(learners, emotions) 
    2121print_results(res) 
    2222 
    23 res = Orange.evaluation.testing.proportion_test(learners, data, 0.5) 
     23res = Orange.evaluation.testing.proportion_test(learners, emotions, 0.5) 
    2424print_results(res) 
    2525 
    26 reses = Orange.evaluation.testing.learning_curve(learners, data) 
     26reses = Orange.evaluation.testing.learning_curve(learners, emotions) 
    2727for res in reses: 
    2828    print_results(res) 
  • docs/reference/rst/code/network-constructor-nx.py

    r9372 r9823  
    2727# plot vertices 
    2828plt.plot(x, y, 'ro') 
    29 plt.savefig("network-constructor-nx.py.png") 
     29plt.savefig("network-constructor-nx.png") 
  • docs/reference/rst/code/network-constructor.py

    r9372 r9823  
    2323# plot vertices 
    2424plt.plot(x, y, 'ro') 
    25 plt.savefig("network-constructor.py.png") 
     25plt.savefig("network-constructor.png") 
  • docs/reference/rst/code/network-graph-analysis.py

    r9372 r9823  
    6060# plot vertices of subnetwork 
    6161plt.plot(x, y, 'ro') 
    62 plt.savefig("network-graph-analysis.py.png") 
     62plt.savefig("network-graph-analysis.png") 
  • docs/reference/rst/code/network-optimization-nx.py

    r9372 r9823  
    3131# plot vertices 
    3232plt.plot(x, y, 'ro') 
    33 plt.savefig("network-optimization-nx.py.png") 
     33plt.savefig("network-optimization-nx.png") 
  • docs/reference/rst/code/network-optimization.py

    r9372 r9823  
    1414networkOptimization = Orange.network.NetworkOptimization(net) 
    1515 
    16 # optimize verices layout with one of included algorithms 
    17 networkOptimization.radial_fruchterman_reingold(100, 1000) 
    18  
    1916# read all edges and plot a line 
    2017for u, v in net.get_edges(): 
     
    2926# plot vertices 
    3027plt.plot(x, y, 'ro') 
    31 plt.savefig("network-optimization.py.png") 
     28plt.savefig("network-optimization.png") 
  • docs/reference/rst/code/optimization-thresholding1.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("bupa") 
     3bupa = Orange.data.Table("bupa") 
    44 
    55learner = Orange.classification.bayes.NaiveLearner() 
     
    77thresh80 = Orange.optimization.ThresholdLearner_fixed(learner=learner,  
    88                                                      threshold=0.8) 
    9 res = Orange.evaluation.testing.cross_validation([learner, thresh, thresh80], table) 
     9res = Orange.evaluation.testing.cross_validation([learner, thresh, thresh80], bupa) 
    1010CAs = Orange.evaluation.scoring.CA(res) 
    1111 
  • docs/reference/rst/code/optimization-thresholding2.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("bupa") 
    4 ri2 = Orange.core.MakeRandomIndices2(table, 0.7) 
    5 train = table.select(ri2, 0) 
    6 test = table.select(ri2, 1) 
     3bupa = Orange.data.Table("bupa") 
     4ri2 = Orange.core.MakeRandomIndices2(bupa, 0.7) 
     5train = bupa.select(ri2, 0) 
     6test = bupa.select(ri2, 1) 
    77 
    88bayes = Orange.classification.bayes.NaiveLearner(train) 
  • docs/reference/rst/code/optimization-tuning1.py

    r9372 r9823  
    22 
    33learner = Orange.classification.tree.TreeLearner() 
    4 data = Orange.data.Table("voting") 
     4voting = Orange.data.Table("voting") 
    55tuner = Orange.optimization.Tune1Parameter(object=learner, 
    66                           parameter="minSubset", 
    77                           values=[1, 2, 3, 4, 5, 10, 15, 20], 
    88                           evaluate = Orange.evaluation.scoring.AUC, verbose=2) 
    9 classifier = tuner(data) 
     9classifier = tuner(voting) 
    1010 
    1111print "Optimal setting: ", learner.minSubset 
    1212 
    1313untuned = Orange.classification.tree.TreeLearner() 
    14 res = Orange.evaluation.testing.cross_validation([untuned, tuner], data) 
     14res = Orange.evaluation.testing.cross_validation([untuned, tuner], voting) 
    1515AUCs = Orange.evaluation.scoring.AUC(res) 
    1616 
     
    1919 
    2020learner = Orange.classification.tree.TreeLearner(minSubset=10).instance() 
    21 data = Orange.data.Table("voting") 
     21voting = Orange.data.Table("voting") 
    2222tuner = Orange.optimization.Tune1Parameter(object=learner, 
    2323                    parameter=["split.continuousSplitConstructor.minSubset",  
     
    2626                    evaluate = Orange.evaluation.scoring.AUC, verbose=2) 
    2727 
    28 classifier = tuner(data) 
     28classifier = tuner(voting) 
    2929 
    3030print "Optimal setting: ", learner.split.continuousSplitConstructor.minSubset 
  • docs/reference/rst/code/optimization-tuningm.py

    r9372 r9823  
    22 
    33learner = Orange.classification.tree.TreeLearner() 
    4 data = Orange.data.Table("voting") 
     4voting = Orange.data.Table("voting") 
    55tuner = Orange.optimization.TuneMParameters(object=learner, 
    66             parameters=[("minSubset", [2, 5, 10, 20]), 
     
    99             evaluate = Orange.evaluation.scoring.AUC) 
    1010 
    11 classifier = tuner(data) 
     11classifier = tuner(voting) 
  • docs/reference/rst/code/orngTree1.py

    r9800 r9823  
    11import Orange 
    22 
    3 data = Orange.data.Table("iris") 
    4 tree = Orange.classification.tree.TreeLearner(data, max_depth=3) 
     3iris = Orange.data.Table("iris") 
     4tree = Orange.classification.tree.TreeLearner(iris, max_depth=3) 
    55 
    66formats = ["", "%V (%M out of %N)", "%V (%^MbA%, %^MbP%)", 
     
    1717 
    1818 
    19 data = Orange.data.Table("housing") 
    20 tree = Orange.classification.tree.TreeLearner(data, max_depth=3) 
     19housing = Orange.data.Table("housing") 
     20tree = Orange.classification.tree.TreeLearner(housing, max_depth=3) 
    2121formats = ["", "%V"] 
    2222for format in formats: 
  • docs/reference/rst/code/orngTree2.py

    r9800 r9823  
    22import re 
    33 
    4 data = Orange.data.Table("iris") 
    5 tree = Orange.classification.tree.TreeLearner(data, max_depth=3) 
     4iris = Orange.data.Table("iris") 
     5tree = Orange.classification.tree.TreeLearner(iris, max_depth=3) 
    66 
    77def get_margin(dist): 
  • docs/reference/rst/code/outlier1.py

    r9372 r9823  
    11import Orange 
    22 
    3 data = Orange.data.Table("bridges") 
     3bridges = Orange.data.Table("bridges") 
    44outlierDet = Orange.preprocess.outliers.OutlierDetection() 
    5 outlierDet.set_examples(data) 
     5outlierDet.set_examples(bridges) 
    66print outlierDet.z_values() 
  • docs/reference/rst/code/outlier2.py

    r9724 r9823  
    11import Orange 
    22 
    3 data = Orange.data.Table("bridges") 
     3bridges = Orange.data.Table("bridges") 
    44outlier_det = Orange.preprocess.outliers.OutlierDetection() 
    5 outlier_det.set_examples(data, Orange.distance.Euclidean(data)) 
     5outlier_det.set_examples(bridges, Orange.distance.instances.EuclideanConstructor(bridges)) 
    66outlier_det.set_knn(3) 
    77z_values = outlier_det.z_values() 
    8 for ex,zv in sorted(zip(data, z_values), key=lambda x: x[1])[-5:]: 
     8for ex,zv in sorted(zip(bridges, z_values), key=lambda x: x[1])[-5:]: 
    99    print ex, "Z-score: %5.3f" % zv 
  • docs/reference/rst/code/pca-scree.py

    r9372 r9823  
    66 
    77import Orange 
    8 table = Orange.data.Table("iris.tab") 
     8iris = Orange.data.Table("iris.tab") 
    99 
    10 pca = Orange.projection.pca.Pca()(table) 
     10pca = Orange.projection.pca.Pca()(iris) 
    1111pca.scree_plot("pca-scree.png") 
  • docs/reference/rst/code/randomindices2.py

    r9696 r9823  
    77import Orange 
    88 
    9 data = Orange.data.Table("lenses") 
     9lenses = Orange.data.Table("lenses") 
    1010 
    1111indices2 = Orange.data.sample.SubsetIndices2(p0=6) 
    1212 
    13 ind = indices2(data) 
     13ind = indices2(lenses) 
    1414print ind 
    15 data0 = data.select(ind, 0) 
    16 data1 = data.select(ind, 1) 
    17 print len(data0), len(data1) 
     15lenses0 = lenses.select(ind, 0) 
     16lenses1 = lenses.select(ind, 1) 
     17print len(lenses0), len(lenses1) 
    1818 
    1919print "\nIndices without playing with random generator" 
    2020for i in range(5): 
    21     print indices2(data) 
     21    print indices2(lenses) 
    2222 
    2323print "\nIndices with random generator" 
    24 indices2.random_generator = Orange.misc.Random(42)     
     24indices2.random_generator = Orange.core.RandomGenerator(42)     
    2525for i in range(5): 
    26     print indices2(data) 
     26    print indices2(lenses) 
    2727 
    2828print "\nIndices with randseed" 
     
    3030indices2.randseed = 42 
    3131for i in range(5): 
    32     print indices2(data) 
     32    print indices2(lenses) 
    3333 
    3434 
    3535print "\nIndices with p0 set as probability (not 'a number of')" 
    3636indices2.p0 = 0.25 
    37 print indices2(data) 
     37print indices2(lenses) 
    3838 
    3939print "\n... with stratification" 
    4040indices2.stratified = indices2.Stratified 
    41 ind = indices2(data) 
     41ind = indices2(lenses) 
    4242print ind 
    43 data2 = data.select(ind) 
    44 od = Orange.core.getClassDistribution(data) 
    45 sd = Orange.core.getClassDistribution(data2) 
     43lenses2 = lenses.select(ind) 
     44od = Orange.core.getClassDistribution(lenses) 
     45sd = Orange.core.getClassDistribution(lenses2) 
    4646od.normalize() 
    4747sd.normalize() 
     
    5151print "\n... and without stratification" 
    5252indices2.stratified = indices2.NotStratified 
    53 print indices2(data) 
    54 ind = indices2(data) 
     53print indices2(lenses) 
     54ind = indices2(lenses) 
    5555print ind 
    56 data2 = data.select(ind) 
    57 od = Orange.core.getClassDistribution(data) 
    58 sd = Orange.core.getClassDistribution(data2) 
     56lenses2 = lenses.select(ind) 
     57od = Orange.core.getClassDistribution(lenses) 
     58sd = Orange.core.getClassDistribution(lenses2) 
    5959od.normalize() 
    6060sd.normalize() 
     
    6464print "\n... stratified 'if possible'" 
    6565indices2.stratified = indices2.StratifiedIfPossible 
    66 print indices2(data) 
     66print indices2(lenses) 
    6767 
    6868print "\n... stratified 'if possible', after removing the first example's class" 
    69 data[0].setclass("?") 
    70 print indices2(data) 
     69lenses[0].setclass("?") 
     70print indices2(lenses) 
  • docs/reference/rst/code/randomindicescv.py

    r9372 r9823  
    66 
    77import Orange 
    8 data = Orange.data.Table("lenses") 
     8lenses = Orange.data.Table("lenses") 
    99print "Indices for ordinary 10-fold CV" 
    10 print Orange.data.sample.SubsetIndicesCV(data) 
     10print Orange.data.sample.SubsetIndicesCV(lenses) 
    1111print "Indices for 5 folds on 10 examples" 
    1212print Orange.data.sample.SubsetIndicesCV(10, folds=5) 
  • docs/reference/rst/code/randomindicesn.py

    r9372 r9823  
    77import Orange 
    88 
    9 data = Orange.data.Table("lenses") 
     9lenses = Orange.data.Table("lenses") 
    1010 
    1111indicesn = Orange.data.sample.SubsetIndicesN(p=[0.5, 0.25]) 
    1212 
    13 ind = indicesn(data) 
     13ind = indicesn(lenses) 
    1414print ind 
    1515 
    1616indicesn = Orange.data.sample.SubsetIndicesN(p=[12, 6]) 
    1717 
    18 ind = indicesn(data) 
     18ind = indicesn(lenses) 
    1919print ind 
  • docs/reference/rst/code/regression-tree-run.py

    r9372 r9823  
    66 
    77import Orange 
    8 table = Orange.data.Table("servo.tab") 
    9 tree = Orange.regression.tree.TreeLearner(table) 
     8servo = Orange.data.Table("servo.tab") 
     9tree = Orange.regression.tree.TreeLearner(servo) 
    1010print tree 
  • docs/reference/rst/code/reliability-basic.py

    r9681 r9823  
    1 # Description: Reliability estimation - basic & fast 
    2 # Category:    evaluation 
    3 # Uses:        housing 
    4 # Referenced:  Orange.evaluation.reliability 
    5 # Classes:     Orange.evaluation.reliability.Mahalanobis, Orange.evaluation.reliability.LocalCrossValidation, Orange.evaluation.reliability.Learner 
    6  
    71import Orange 
    82 
    9 data = Orange.data.Table("housing.tab") 
     3housing = Orange.data.Table("housing.tab") 
    104 
    115knn = Orange.classification.knn.kNNLearner() 
     
    1610reliability = Orange.evaluation.reliability.Learner(knn, estimators = estimators) 
    1711 
    18 restimator = reliability(data) 
    19 instance = data[0] 
     12restimator = reliability(housing) 
     13instance = housing[0] 
    2014 
    2115value, probability = restimator(instance, result_type=Orange.core.GetBoth) 
  • docs/reference/rst/code/reliability-long.py

    r9683 r9823  
    1 # Description: Reliability estimation 
    2 # Category:    evaluation 
    3 # Uses:        prostate 
    4 # Referenced:  Orange.evaluation.reliability 
    5 # Classes:     Orange.evaluation.reliability.Learner 
     1import Orange 
    62 
    7 import Orange 
    8 Orange.evaluation.reliability.select_with_repeat.random_generator = None 
    9 Orange.evaluation.reliability.select_with_repeat.randseed = 42 
    10  
    11 import Orange 
    12 table = Orange.data.Table("prostate.tab") 
     3prostate = Orange.data.Table("prostate.tab") 
    134 
    145knn = Orange.classification.knn.kNNLearner() 
    156reliability = Orange.evaluation.reliability.Learner(knn) 
    167 
    17 res = Orange.evaluation.testing.cross_validation([reliability], table) 
     8res = Orange.evaluation.testing.cross_validation([reliability], prostate) 
    189 
    1910reliability_res = Orange.evaluation.reliability.get_pearson_r(res) 
     
    2213print "Estimate               r       p" 
    2314for estimate in reliability_res: 
    24     print "%-20s %7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]], 
     15    print "%-20s %7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]], \ 
    2516                                 estimate[0], estimate[1]) 
    2617 
    2718reliability = Orange.evaluation.reliability.Learner(knn, estimators=[Orange.evaluation.reliability.SensitivityAnalysis()]) 
    2819 
    29 res = Orange.evaluation.testing.cross_validation([reliability], table) 
     20res = Orange.evaluation.testing.cross_validation([reliability], prostate) 
    3021 
    3122reliability_res = Orange.evaluation.reliability.get_pearson_r(res) 
     
    3425print "Estimate               r       p" 
    3526for estimate in reliability_res: 
    36     print "%-20s %7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]], 
     27    print "%-20s %7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]], \ 
    3728                                 estimate[0], estimate[1]) 
    3829 
    39 indices = Orange.core.MakeRandomIndices2(table, p0=0.7) 
    40 train = table.select(indices, 0) 
    41 test = table.select(indices, 1) 
     30indices = Orange.core.MakeRandomIndices2(prostate, p0=0.7) 
     31train = prostate.select(indices, 0) 
     32test = prostate.select(indices, 1) 
    4233 
    4334reliability = Orange.evaluation.reliability.Learner(knn, icv=True) 
  • docs/reference/rst/code/reliability-run.py

    r9683 r9823  
    1 # Description: Reliability estimation with cross-validation 
    2 # Category:    evaluation 
    3 # Uses:        housing 
    4 # Referenced:  Orange.evaluation.reliability 
    5 # Classes:     Orange.evaluation.reliability.Learner 
    6  
    71import Orange 
    8 Orange.evaluation.reliability.select_with_repeat.random_generator = None 
    9 Orange.evaluation.reliability.select_with_repeat.randseed = 42 
    10  
    11 import Orange 
    12 table = Orange.data.Table("housing.tab") 
     2housing = Orange.data.Table("housing.tab") 
    133 
    144knn = Orange.classification.knn.kNNLearner() 
    155reliability = Orange.evaluation.reliability.Learner(knn) 
    166 
    17 results = Orange.evaluation.testing.cross_validation([reliability], table) 
     7results = Orange.evaluation.testing.cross_validation([reliability], housing) 
    188 
    19 for i, instance in enumerate(results.results[:10]): 
    20     print "Instance", i 
    21     for estimate in instance.probabilities[0].reliability_estimate: 
    22         print "  ", estimate.method_name, estimate.estimate 
     9for estimate in results.results[0].probabilities[0].reliability_estimate: 
     10    print estimate.method_name, estimate.estimate 
  • docs/reference/rst/code/rules-cn2.py

    r9372 r9823  
    77import Orange 
    88# Read some data 
    9 table = Orange.data.Table("titanic") 
     9titanic = Orange.data.Table("titanic") 
    1010 
    1111# construct the learning algorithm and use it to induce a classifier 
    1212cn2_learner = Orange.classification.rules.CN2Learner() 
    13 cn2_clasifier = cn2_learner(table) 
     13cn2_clasifier = cn2_learner(titanic) 
    1414 
    1515# ... or, in a single step. 
    16 cn2_classifier = Orange.classification.rules.CN2Learner(table) 
     16cn2_classifier = Orange.classification.rules.CN2Learner(titanic) 
    1717 
    1818# All rule-base classifiers can have their rules printed out like this: 
  • docs/reference/rst/code/rules-customized.py

    r9372 r9823  
    1111learner.rule_finder.evaluator = Orange.classification.rules.MEstimateEvaluator(m=50) 
    1212 
    13 table =  Orange.data.Table("titanic") 
    14 classifier = learner(table) 
     13titanic =  Orange.data.Table("titanic") 
     14classifier = learner(titanic) 
    1515 
    1616for r in classifier.rules: 
     
    2323    Orange.classification.rules.RuleBeamFilter_Width(width = 50) 
    2424 
    25 classifier = learner(table) 
     25classifier = learner(titanic) 
    2626 
    2727for r in classifier.rules: 
  • docs/reference/rst/code/scoring-all.py

    r9372 r9823  
    66 
    77import Orange 
    8 table = Orange.data.Table("voting") 
     8voting = Orange.data.Table("voting") 
    99 
    1010def print_best_3(ma): 
     
    1313 
    1414print 'Feature scores for best three features (with score_all):' 
    15 ma = Orange.feature.scoring.score_all(table) 
     15ma = Orange.feature.scoring.score_all(voting) 
    1616print_best_3(ma) 
    1717 
     
    2020print 'Feature scores for best three features (scored individually):' 
    2121meas = Orange.feature.scoring.Relief(k=20, m=50) 
    22 mr = [ (a.name, meas(a, table)) for a in table.domain.attributes ] 
     22mr = [ (a.name, meas(a, voting)) for a in voting.domain.attributes] 
    2323mr.sort(key=lambda x: -x[1]) #sort decreasingly by the score 
    2424print_best_3(mr) 
  • docs/reference/rst/code/scoring-calls.py

    r9372 r9823  
    66 
    77import Orange 
    8 table = Orange.data.Table("titanic") 
     8titanic = Orange.data.Table("titanic") 
    99meas = Orange.feature.scoring.GainRatio() 
    1010 
    1111print "Call with variable and data table" 
    12 print meas(0, table) 
     12print meas(0, titanic) 
    1313 
    1414print "Call with variable and domain contingency" 
    15 domain_cont = Orange.statistics.contingency.Domain(table) 
     15domain_cont = Orange.statistics.contingency.Domain(titanic) 
    1616print meas(0, domain_cont) 
    1717 
    1818print "Call with contingency and class distribution" 
    19 cont = Orange.statistics.contingency.VarClass(0, table) 
     19cont = Orange.statistics.contingency.VarClass(0, titanic) 
    2020class_dist = Orange.statistics.distribution.Distribution( \ 
    21     table.domain.class_var, table) 
     21    titanic.domain.class_var, titanic) 
    2222print meas(cont, class_dist) 
  • docs/reference/rst/code/scoring-diff-measures.py

    r9372 r9823  
    77import Orange 
    88import random 
    9 table = Orange.data.Table("measure") 
     9data = Orange.data.Table("measure") 
    1010 
    11 table2 = Orange.data.Table(table) 
     11data2 = Orange.data.Table(data) 
    1212nulls = [(0, 1, 24, 25), (24, 25), range(24, 34), (24, 25)] 
    1313for attr in range(len(nulls)): 
    1414    for e in nulls[attr]: 
    15         table2[e][attr]="?" 
     15        data2[e][attr]="?" 
    1616 
    17 names = [a.name for a in table.domain.attributes] 
     17names = [a.name for a in data.domain.attributes] 
    1818attrs = len(names) 
    1919print 
     
    2222 
    2323def printVariants(meas): 
    24     print fstr % (("- no unknowns:",) + tuple([meas(i, table) for i in range(attrs)])) 
     24    print fstr % (("- no unknowns:",) + tuple([meas(i, data) for i in range(attrs)])) 
    2525 
    2626    meas.unknowns_treatment = meas.IgnoreUnknowns 
    27     print fstr % (("- ignore unknowns:",) + tuple([meas(i, table2) for i in range(attrs)])) 
     27    print fstr % (("- ignore unknowns:",) + tuple([meas(i, data2) for i in range(attrs)])) 
    2828 
    2929    meas.unknowns_treatment = meas.ReduceByUnknowns 
    30     print fstr % (("- reduce unknowns:",) + tuple([meas(i, table2) for i in range(attrs)])) 
     30    print fstr % (("- reduce unknowns:",) + tuple([meas(i, data2) for i in range(attrs)])) 
    3131 
    3232    meas.unknowns_treatment = meas.UnknownsToCommon 
    33     print fstr % (("- unknowns to common:",) + tuple([meas(i, table2) for i in range(attrs)])) 
     33    print fstr % (("- unknowns to common:",) + tuple([meas(i, data2) for i in range(attrs)])) 
    3434 
    3535    meas.unknowns_treatment = meas.UnknownsAsValue 
    36     print fstr % (("- unknowns as value:",) + tuple([meas(i, table2) for i in range(attrs)])) 
     36    print fstr % (("- unknowns as value:",) + tuple([meas(i, data2) for i in range(attrs)])) 
    3737    print 
    3838 
     
    4848print "Relief" 
    4949meas = Orange.feature.scoring.Relief() 
    50 print fstr % (("- no unknowns:",) + tuple([meas(i, table) for i in range(attrs)])) 
    51 print fstr % (("- with unknowns:",) + tuple([meas(i, table2) for i in range(attrs)])) 
     50print fstr % (("- no unknowns:",) + tuple([meas(i, data) for i in range(attrs)])) 
     51print fstr % (("- with unknowns:",) + tuple([meas(i, data2) for i in range(attrs)])) 
    5252print 
    5353 
  • docs/reference/rst/code/scoring-info-iris.py

    r9372 r9823  
    66 
    77import Orange 
    8 table = Orange.data.Table("iris") 
     8iris = Orange.data.Table("iris") 
    99 
    10 d1 = Orange.feature.discretization.EntropyDiscretization("petal length", table) 
    11 print Orange.feature.scoring.InfoGain(d1, table) 
     10d1 = Orange.feature.discretization.EntropyDiscretization("petal length", iris) 
     11print Orange.feature.scoring.InfoGain(d1, iris) 
    1212 
    13 table = Orange.data.Table("iris") 
     13iris = Orange.data.Table("iris") 
    1414meas = Orange.feature.scoring.Relief() 
    15 for t in meas.threshold_function("petal length", table): 
     15for t in meas.threshold_function("petal length", iris): 
    1616    print "%5.3f: %5.3f" % t 
    1717 
    18 thresh, score, distr = meas.best_threshold("petal length", table) 
     18thresh, score, distr = meas.best_threshold("petal length", iris) 
    1919print "\nBest threshold: %5.3f (score %5.3f)" % (thresh, score) 
  • 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) 
  • docs/reference/rst/code/scoring-relief-caching.py

    r9372 r9823  
    66 
    77import orange 
    8 data = orange.ExampleTable("iris") 
     8iris = orange.ExampleTable("iris") 
    99 
    1010r1 = orange.MeasureAttribute_relief() 
    1111r2 = orange.MeasureAttribute_relief(check_cached_data = False) 
    1212 
    13 print "%.3f\t%.3f" % (r1(0, data), r2(0, data)) 
    14 for ex in data: 
     13print "%.3f\t%.3f" % (r1(0, iris), r2(0, iris)) 
     14for ex in iris: 
    1515    ex[0] = 0 
    16 print "%.3f\t%.3f" % (r1(0, data), r2(0, data)) 
     16print "%.3f\t%.3f" % (r1(0, iris), r2(0, iris)) 
  • docs/reference/rst/code/scoring-relief-gainRatio.py

    r9372 r9823  
    66 
    77import Orange 
    8 table = Orange.data.Table("voting") 
     8voting = Orange.data.Table("voting") 
    99 
    1010print 'Relief GainRt Feature' 
    11 ma_def = Orange.feature.scoring.score_all(table) 
     11ma_def = Orange.feature.scoring.score_all(voting) 
    1212gr = Orange.feature.scoring.GainRatio() 
    13 ma_gr  = Orange.feature.scoring.score_all(table, gr) 
     13ma_gr  = Orange.feature.scoring.score_all(voting, gr) 
    1414for i in range(5): 
    1515    print "%5.3f  %5.3f  %s" % (ma_def[i][1], ma_gr[i][1], ma_def[i][0]) 
  • docs/reference/rst/code/selection-bayes.py

    r9661 r9823  
    33# Uses:        voting 
    44# Referenced:  Orange.feature.html#selection 
    5 # Classes:     Orange.feature.scoring.score_all, Orange.feature.selection.best_n 
     5# Classes:     Orange.feature.scoring.score_all, Orange.feature.selection.bestNAtts 
    66 
    77import Orange 
     
    1515        else: 
    1616            return learner 
    17  
     17     
    1818    def __init__(self, name='Naive Bayes with FSS', N=5): 
    1919        self.name = name 
    2020        self.N = 5 
    21  
    22     def __call__(self, data, weight=None): 
    23         ma = Orange.feature.scoring.score_all(data) 
    24         filtered = Orange.feature.selection.select_best_n(data, ma, self.N) 
     21       
     22    def __call__(self, table, weight=None): 
     23        ma = Orange.feature.scoring.score_all(table) 
     24        filtered = Orange.feature.selection.selectBestNAtts(table, ma, self.N) 
    2525        model = Orange.classification.bayes.NaiveLearner(filtered) 
    2626        return BayesFSS_Classifier(classifier=model, N=self.N, name=self.name) 
     
    2929    def __init__(self, **kwds): 
    3030        self.__dict__.update(kwds) 
    31  
    32     def __call__(self, example, resultType=Orange.core.GetValue): 
     31     
     32    def __call__(self, example, resultType = Orange.core.GetValue): 
    3333        return self.classifier(example, resultType) 
    3434 
  • docs/reference/rst/code/selection-filtered-learner.py

    r9661 r9823  
    88# Classes:     Orange.feature.selection.FilteredLearner 
    99 
    10 import Orange 
    11  
     10import Orange, orngTest, orngStat 
    1211voting = Orange.data.Table("voting") 
    1312 
    1413nb = Orange.classification.bayes.NaiveLearner() 
    15 fl = Orange.feature.selection.FilteredLearner(nb, 
    16      filter=Orange.feature.selection.FilterBestN(n=1), name='filtered') 
     14fl = Orange.feature.selection.FilteredLearner(nb,  
     15     filter=Orange.feature.selection.FilterBestNAtts(n=1), name='filtered') 
    1716learners = (Orange.classification.bayes.NaiveLearner(name='bayes'), fl) 
    18 results = Orange.evaluation.testing.cross_validation(learners, voting, storeClassifiers=1) 
     17results = orngTest.crossValidation(learners, voting, storeClassifiers=1) 
    1918 
    2019# output the results 
    2120print "Learner      CA" 
    2221for i in range(len(learners)): 
    23     print "%-12s %5.3f" % (learners[i].name, Orange.evaluation.scoring.CA(results)[i]) 
     22    print "%-12s %5.3f" % (learners[i].name, orngStat.CA(results)[i]) 
    2423 
    2524# find out which attributes were retained by filtering 
  • docs/reference/rst/code/simple_tree_random_forest.py

    r9372 r9823  
    2626learners = [ rf_def, rf_simple ] 
    2727 
    28 table = Orange.data.Table("iris") 
    29 results = Orange.evaluation.testing.cross_validation(learners, table, folds=3) 
     28iris = Orange.data.Table("iris") 
     29results = Orange.evaluation.testing.cross_validation(learners, iris, folds=3) 
    3030print "Learner  CA     Brier  AUC" 
    3131for i in range(len(learners)): 
     
    4040for l in learners: 
    4141    t = time.time() 
    42     l(table) 
     42    l(iris) 
    4343    print l.name, time.time() - t 
  • docs/reference/rst/code/simple_tree_regression.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("housing.tab") 
     3housing = Orange.data.Table("housing.tab") 
    44learner = Orange.regression.tree.SimpleTreeLearner 
    5 res = Orange.evaluation.testing.cross_validation([learner], table) 
     5res = Orange.evaluation.testing.cross_validation([learner], housing) 
    66print Orange.evaluation.scoring.MSE(res)[0] 
  • docs/reference/rst/code/som-classifier.py

    r9372 r9823  
    88import random 
    99learner = Orange.projection.som.SOMSupervisedLearner(map_shape=(4, 4)) 
    10 data = Orange.data.Table("iris.tab") 
    11 classifier = learner(data) 
     10iris = Orange.data.Table("iris.tab") 
     11classifier = learner(iris) 
    1212random.seed(50) 
    13 for d in random.sample(data, 5): 
     13for d in random.sample(iris, 5): 
    1414    print "%-15s originally %-15s" % (classifier(d), d.getclass()) 
  • docs/reference/rst/code/statistics-contingency.py

    r9372 r9823  
    1 import Orange.statistics.contingency 
     1import Orange 
    22 
    3 table = Orange.data.Table("monks-1.tab") 
    4 cont = Orange.statistics.contingency.VarClass("e", table) 
     3monks = Orange.data.Table("monks-1.tab") 
     4cont = Orange.statistics.contingency.VarClass("e", monks) 
    55for val, dist in cont.items(): 
    66    print val, dist 
  • docs/reference/rst/code/statistics-contingency2.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("monks-1.tab") 
    4 cont = Orange.statistics.contingency.Table(table.domain["e"], table.domain.classVar) 
    5 for ins in table: 
     3monks = Orange.data.Table("monks-1.tab") 
     4cont = Orange.statistics.contingency.Table(monks.domain["e"], monks.domain.classVar) 
     5for ins in monks: 
    66    cont [ins["e"]] [ins.get_class()] += 1 
    77 
     
    1212print 
    1313 
    14 for ins in table: 
     14for ins in monks: 
    1515    cont.add(ins["e"], ins.get_class()) 
  • docs/reference/rst/code/statistics-contingency3.py

    r9372 r9823  
    11import Orange.statistics.contingency 
    22 
    3 table = Orange.data.Table("monks-1.tab") 
    4 cont = Orange.statistics.contingency.VarClass("e", table) 
     3monks = Orange.data.Table("monks-1.tab") 
     4cont = Orange.statistics.contingency.VarClass("e", monks) 
    55 
    66print "Inner variable: ", cont.inner_variable.name 
     
    2424print 
    2525 
    26 cont = Orange.statistics.contingency.VarClass(table.domain["e"], 
    27                                               table.domain.class_var) 
    28 for ins in table: 
     26cont = Orange.statistics.contingency.VarClass(monks.domain["e"], 
     27                                              monks.domain.class_var) 
     28for ins in monks: 
    2929    cont.add_var_class(ins["e"], ins.getclass()) 
    3030 
  • docs/reference/rst/code/statistics-contingency4.py

    r9372 r9823  
    11import Orange.statistics.contingency 
    22 
    3 table = Orange.data.Table("monks-1.tab") 
    4 cont = Orange.statistics.contingency.ClassVar("e", table) 
     3monks = Orange.data.Table("monks-1.tab") 
     4cont = Orange.statistics.contingency.ClassVar("e", monks) 
    55 
    66print "Inner variable: ", cont.inner_variable.name 
     
    2323print 
    2424 
    25 cont = Orange.statistics.contingency.ClassVar(table.domain["e"], table.domain.class_var) 
    26 for ins in table: 
     25cont = Orange.statistics.contingency.ClassVar(monks.domain["e"], monks.domain.class_var) 
     26for ins in monks: 
    2727    cont.add_var_class(ins["e"], ins.get_class()) 
    2828 
  • docs/reference/rst/code/statistics-contingency5.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("bridges.tab") 
    4 cont = Orange.statistics.contingency.VarVar("SPAN", "MATERIAL", table) 
     3bridges = Orange.data.Table("bridges.tab") 
     4cont = Orange.statistics.contingency.VarVar("SPAN", "MATERIAL", bridges) 
    55 
    66print "Distributions:" 
     
    1717    print 
    1818 
    19 cont = Orange.statistics.contingency.VarVar(table.domain["SPAN"], table.domain["MATERIAL"]) 
    20 for ins in table: 
     19cont = Orange.statistics.contingency.VarVar(bridges.domain["SPAN"], bridges.domain["MATERIAL"]) 
     20for ins in bridges: 
    2121    cont.add(ins["SPAN"], ins["MATERIAL"]) 
    2222 
  • docs/reference/rst/code/statistics-contingency6.py

    r9749 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("iris.tab") 
    4 cont = Orange.statistics.contingency.VarClass(0, table) 
     3iris = Orange.data.Table("iris.tab") 
     4cont = Orange.statistics.contingency.VarClass(0, iris) 
    55 
    66print "Contingency items:" 
     
    1515 
    1616 
    17 midkey = (cont.keys()[0] + cont.keys()[1]) / 2.0 
     17midkey = (cont.keys()[0] + cont.keys()[1])/2.0 
    1818print "cont[%5.3f] =" % midkey, cont[midkey] 
    1919 
  • docs/reference/rst/code/statistics-contingency7.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("iris") 
    4 cont = Orange.statistics.contingency.ClassVar("sepal length", table) 
     3iris = Orange.data.Table("iris") 
     4cont = Orange.statistics.contingency.ClassVar("sepal length", iris) 
    55 
    66print "Inner variable: ", cont.inner_variable.name 
     
    2121print 
    2222 
    23 cont = Orange.statistics.contingency.ClassVar(table.domain["sepal length"],  
    24                                               table.domain.class_var) 
    25 for ins in table: 
     23cont = Orange.statistics.contingency.ClassVar(iris.domain["sepal length"],  
     24                                              iris.domain.class_var) 
     25for ins in iris: 
    2626    cont.add_var_class(ins["sepal length"], ins.get_class()) 
    2727 
  • docs/reference/rst/code/statistics-contingency8.py

    r9372 r9823  
    11import Orange 
    22 
    3 table = Orange.data.Table("monks-1.tab") 
     3monks = Orange.data.Table("monks-1.tab") 
    44 
    55print "Distributions of classes given the feature value" 
    6 dc = Orange.statistics.contingency.Domain(table) 
     6dc = Orange.statistics.contingency.Domain(monks) 
    77print "a: ", dc["a"] 
    88print "b: ", dc["b"] 
     
    1111 
    1212print "Distributions of feature values given the class value" 
    13 dc = Orange.statistics.contingency.Domain(table, classIsOuter = 1) 
     13dc = Orange.statistics.contingency.Domain(monks, classIsOuter = 1) 
    1414print "a: ", dc["a"] 
    1515print "b: ", dc["b"] 
  • docs/reference/rst/code/svm-custom-kernel.py

    r9724 r9823  
    33 
    44from Orange.classification.svm import SVMLearner, kernels 
    5 from Orange.distance import Euclidean 
    6 from Orange.distance import Hamming 
     5from Orange.distance.instances import EuclideanConstructor 
     6from Orange.distance.instances import HammingConstructor 
    77 
    8 table = data.Table("iris.tab") 
     8iris = data.Table("iris.tab") 
    99l1 = SVMLearner() 
    10 l1.kernel_func = kernels.RBFKernelWrapper(Euclidean(table), gamma=0.5) 
     10l1.kernel_func = kernels.RBFKernelWrapper(EuclideanConstructor(iris), gamma=0.5) 
    1111l1.kernel_type = SVMLearner.Custom 
    1212l1.probability = True 
    13 c1 = l1(table) 
     13c1 = l1(iris) 
    1414l1.name = "SVM - RBF(Euclidean)" 
    1515 
    1616l2 = SVMLearner() 
    17 l2.kernel_func = kernels.RBFKernelWrapper(Hamming(table), gamma=0.5) 
     17l2.kernel_func = kernels.RBFKernelWrapper(HammingConstructor(iris), gamma=0.5) 
    1818l2.kernel_type = SVMLearner.Custom 
    1919l2.probability = True 
    20 c2 = l2(table) 
     20c2 = l2(iris) 
    2121l2.name = "SVM - RBF(Hamming)" 
    2222 
    2323l3 = SVMLearner() 
    2424l3.kernel_func = kernels.CompositeKernelWrapper( 
    25     kernels.RBFKernelWrapper(Euclidean(table), gamma=0.5), 
    26     kernels.RBFKernelWrapper(Hamming(table), gamma=0.5), l=0.5) 
     25    kernels.RBFKernelWrapper(EuclideanConstructor(iris), gamma=0.5), 
     26    kernels.RBFKernelWrapper(HammingConstructor(iris), gamma=0.5), l=0.5) 
    2727l3.kernel_type = SVMLearner.Custom 
    2828l3.probability = True 
    29 c3 = l1(table) 
     29c3 = l1(iris) 
    3030l3.name = "SVM - Composite" 
    3131 
    32 tests = evaluation.testing.cross_validation([l1, l2, l3], table, folds=5) 
     32tests = evaluation.testing.cross_validation([l1, l2, l3], iris, folds=5) 
    3333[ca1, ca2, ca3] = evaluation.scoring.CA(tests) 
    3434 
  • docs/reference/rst/code/svm-easy.py

    r9372 r9823  
    22from Orange.classification import svm 
    33 
    4 table = data.Table("vehicle.tab") 
     4vehicle = data.Table("vehicle.tab") 
    55 
    66svm_easy = svm.SVMLearnerEasy(name="svm easy", folds=3) 
     
    1010from Orange.evaluation import testing, scoring 
    1111 
    12 results = testing.cross_validation(learners, table, folds=5) 
     12results = testing.cross_validation(learners, vehicle, folds=5) 
    1313print "Name     CA        AUC" 
    1414for learner,CA,AUC in zip(learners, scoring.CA(results), scoring.AUC(results)): 
  • docs/reference/rst/code/svm-linear-weights.py

    r9372 r9823  
    22from Orange.classification import svm 
    33 
    4 table = data.Table("brown-selected") 
    5 classifier = svm.SVMLearner(table,  
     4brown = data.Table("brown-selected") 
     5classifier = svm.SVMLearner(brown,  
    66                            kernel_type=svm.kernels.Linear,  
    77                            normalization=False) 
  • docs/reference/rst/code/svm-recursive-feature-elimination.py

    r9372 r9823  
    22from Orange.classification import svm 
    33 
    4 table = data.Table("brown-selected") 
    5 print table.domain 
     4brown = data.Table("brown-selected") 
     5print brown.domain 
    66 
    77rfe = svm.RFE() 
    8 newdata = rfe(table, 10) 
     8newdata = rfe(brown, 10) 
    99print newdata.domain 
  • docs/reference/rst/code/symmatrix.py

    r9372 r9823  
    1 import Orange.data 
     1import Orange 
    22 
    33m = Orange.data.SymMatrix(4) 
  • docs/reference/rst/code/testing-test.py

    r9696 r9823  
    44import Orange.evaluation.testing 
    55 
    6 table = Orange.data.Table("voting") 
     6voting = Orange.data.Table("voting") 
    77 
    88bayes = Orange.classification.bayes.NaiveLearner(name="bayes") 
     
    1919print "\nproportionsTest that will always give the same results" 
    2020for i in range(3): 
    21     res = Orange.evaluation.testing.proportion_test(learners, table, 0.7) 
     21    res = Orange.evaluation.testing.proportion_test(learners, voting, 0.7) 
    2222    printResults(res) 
    2323 
    2424print "\nproportionsTest that will give different results, \ 
    2525but the same each time the script is run" 
    26 myRandom = Orange.misc.Random() 
     26myRandom = Orange.core.RandomGenerator() 
    2727for i in range(3): 
    28     res = Orange.evaluation.testing.proportion_test(learners, table, 0.7, 
    29         random_generator=myRandom) 
     28    res = Orange.evaluation.testing.proportion_test(learners, voting, 0.7, 
     29        randomGenerator=myRandom) 
    3030    printResults(res) 
    3131# End 
     
    3434    print "\nproportionsTest that will give different results each time it is run" 
    3535    for i in range(3): 
    36         res = Orange.evaluation.testing.proportion_test(learners, table, 0.7, 
     36        res = Orange.evaluation.testing.proportion_test(learners, voting, 0.7, 
    3737            randseed=random.randint(0, 100)) 
    3838        printResults(res) 
     
    4040 
    4141print "\nproportionsTest + storing classifiers" 
    42 res = Orange.evaluation.testing.proportion_test(learners, table, 0.7, 100, 
     42res = Orange.evaluation.testing.proportion_test(learners, voting, 0.7, 100, 
    4343    storeClassifiers=1) 
    4444print "#iter %i, #classifiers %i" % \ 
     
    4646 
    4747print "\nGood old 10-fold cross validation" 
    48 res = Orange.evaluation.testing.cross_validation(learners, table) 
     48res = Orange.evaluation.testing.cross_validation(learners, voting) 
    4949printResults(res) 
    5050 
    5151print "\nLearning curve" 
    5252prop = Orange.core.frange(0.2, 1.0, 0.2) 
    53 res = Orange.evaluation.testing.learning_curve_n(learners, table, folds=5, 
     53res = Orange.evaluation.testing.learning_curve_n(learners, voting, folds=5, 
    5454    proportions=prop) 
    5555for i in range(len(prop)): 
     
    5959 
    6060print "\nLearning curve with pre-separated data" 
    61 indices = Orange.core.MakeRandomIndices2(table, p0=0.7) 
    62 train = table.select(indices, 0) 
    63 test = table.select(indices, 1) 
     61indices = Orange.core.MakeRandomIndices2(voting, p0=0.7) 
     62train = voting.select(indices, 0) 
     63test = voting.select(indices, 1) 
    6464res = Orange.evaluation.testing.learning_curve_with_test_data(learners, train, 
    6565    test, times=5, proportions=prop) 
     
    7474 
    7575print "\nLearning and testing on the same data" 
    76 res = Orange.evaluation.testing.learn_and_test_on_learn_data(learners, table) 
     76res = Orange.evaluation.testing.learn_and_test_on_learn_data(learners, voting) 
    7777printResults(res) 
  • docs/reference/rst/code/tree2.py

    r9567 r9823  
    77 
    88import Orange 
    9 data = Orange.data.Table("iris.tab") 
     9iris = Orange.data.Table("iris.tab") 
    1010 
    1111print "BIG TREE:" 
    12 tree1 = Orange.classification.tree.TreeLearner(data) 
     12tree1 = Orange.classification.tree.TreeLearner(iris) 
    1313print tree1.to_string(leaf_str="%m", node_str=".") 
    1414 
    1515print "\nPRE-PRUNED TREE:" 
    16 tree2 = Orange.classification.tree.TreeLearner(data, max_majority=0.7) 
     16tree2 = Orange.classification.tree.TreeLearner(iris, max_majority=0.7) 
    1717print tree2.to_string(leaf_str="%m", node_str=".") 
    1818 
  • docs/reference/rst/code/tree3.py

    r9372 r9823  
    1010seed(0) 
    1111 
    12 data = Orange.data.Table("iris.tab") 
     12iris = Orange.data.Table("iris.tab") 
    1313 
    1414print "SOME RANDOMNESS IN STOPING:" 
    1515def_stop = Orange.classification.tree.StopCriteria() 
    1616f = lambda examples, weightID, contingency: def_stop(examples, weightID, contingency) or randint(1, 5) == 1 
    17 l = Orange.classification.tree.TreeLearner(data, stop=f) 
     17l = Orange.classification.tree.TreeLearner(iris, stop=f) 
    1818print l 
    1919 
    2020print "\nRANDOM STOPING:" 
    2121f = lambda x,y,z: randint(1, 5)==1 
    22 l = Orange.classification.tree.TreeLearner(data, stop=f) 
     22l = Orange.classification.tree.TreeLearner(iris, stop=f) 
    2323print l 
  • docs/reference/rst/code/tree_c45.py

    r9372 r9823  
    77import Orange 
    88 
    9 data = Orange.data.Table("iris") 
    10 tree = Orange.classification.tree.C45Learner(data) 
     9iris = Orange.data.Table("iris") 
     10tree = Orange.classification.tree.C45Learner(iris) 
    1111 
    1212print "\n\nC4.5 with default arguments" 
    13 for i in data[:5]: 
     13for i in iris[:5]: 
    1414    print tree(i), i.getclass() 
    1515 
    1616print "\n\nC4.5 with m=100" 
    17 tree = Orange.classification.tree.C45Learner(data, m=100) 
    18 for i in data[:5]: 
     17tree = Orange.classification.tree.C45Learner(iris, m=100) 
     18for i in iris[:5]: 
    1919    print tree(i), i.getclass() 
    2020 
    2121print "\n\nC4.5 with minObjs=100" 
    22 tree = Orange.classification.tree.C45Learner(data, minObjs=100) 
    23 for i in data[:5]: 
     22tree = Orange.classification.tree.C45Learner(iris, minObjs=100) 
     23for i in iris[:5]: 
    2424    print tree(i), i.getclass() 
    2525 
     
    2727lrn = Orange.classification.tree.C45Learner() 
    2828lrn.commandline("-m 1 -s") 
    29 tree = lrn(data) 
    30 for i in data: 
     29tree = lrn(iris) 
     30for i in iris: 
    3131    if i.getclass() != tree(i): 
    3232        print i, tree(i) 
    3333 
    34 tree = Orange.classification.tree.C45Learner(data) 
     34tree = Orange.classification.tree.C45Learner(iris) 
    3535print tree 
    3636print 
     
    3838 
    3939res = Orange.evaluation.testing.cross_validation([Orange.classification.tree.C45Learner(),  
    40     Orange.classification.tree.C45Learner(convertToOrange=1)], data) 
     40    Orange.classification.tree.C45Learner(convertToOrange=1)], iris) 
    4141print "Classification accuracy: %5.3f (converted to tree: %5.3f)" % tuple(Orange.evaluation.scoring.CA(res)) 
    4242print "Brier score: %5.3f (converted to tree: %5.3f)" % tuple(Orange.evaluation.scoring.Brier_score(res)) 
  • docs/reference/rst/code/treelearner.py

    r9372 r9823  
    77import Orange 
    88 
    9 data = Orange.data.Table("lenses") 
     9lenses = Orange.data.Table("lenses") 
    1010learner = Orange.classification.tree.TreeLearner() 
    1111 
     
    4040print "\n\nTree with minExamples = 5.0" 
    4141learner.stop.min_examples = 5.0 
    42 tree = learner(data) 
     42tree = learner(lenses) 
    4343print tree 
    4444 
    4545print "\n\nTree with maxMajority = 0.5" 
    4646learner.stop.max_majority = 0.5 
    47 tree = learner(data) 
     47tree = learner(lenses) 
    4848print tree 
  • docs/reference/rst/code/treestructure.py

    r9372 r9823  
    77import Orange 
    88 
    9 data = Orange.data.Table("lenses") 
    10 tree_classifier = Orange.classification.tree.TreeLearner(data) 
     9lenses = Orange.data.Table("lenses") 
     10tree_classifier = Orange.classification.tree.TreeLearner(lenses) 
    1111 
    1212def tree_size(node): 
  • docs/reference/rst/code/variable-get_value_from.py

    r9372 r9823  
    1313        return e2("not 1")  
    1414 
    15 data = Orange.data.Table("monks-1") 
     15monks = Orange.data.Table("monks-1") 
    1616e2 = Orange.data.variable.Discrete("e2", values=["not 1", "1"])     
    1717e2.get_value_from = checkE  
    1818 
    19 print Orange.core.MeasureAttribute_info(e2, data) 
     19print Orange.core.MeasureAttribute_info(e2, monks) 
    2020 
    21 dist = Orange.core.Distribution(e2, data) 
     21dist = Orange.core.Distribution(e2, monks) 
    2222print dist  
    2323 
    2424# Split the data into training and testing set 
    25 indices = Orange.core.MakeRandomIndices2(data, p0=0.7) 
    26 train_data = data.select(indices, 0) 
    27 test_data = data.select(indices, 1) 
     25indices = Orange.core.MakeRandomIndices2(monks, p0=0.7) 
     26train_data = monks.select(indices, 0) 
     27test_data = monks.select(indices, 1) 
    2828 
    2929# Convert the training set to a new domain 
    30 new_domain = Orange.data.Domain([data.domain["a"], data.domain["b"], e2, data.domain.class_var]) 
     30new_domain = Orange.data.Domain([monks.domain["a"], monks.domain["b"], e2, monks.domain.class_var]) 
    3131new_train = Orange.data.Table(new_domain, train_data) 
    3232 
Note: See TracChangeset for help on using the changeset viewer.