source: orange/Orange/testing/regression/tests_20/modules_test.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 2.5 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line 
1import orange, orngTest, orngStat
2import random
3
4data = orange.ExampleTable("voting")
5
6bayes = orange.BayesLearner(name = "bayes")
7tree = orange.TreeLearner(name = "tree")
8majority = orange.MajorityLearner(name = "default")
9learners = [bayes, tree, majority]
10names = [x.name for x in learners]
11
12def printResults(res):
13    CAs = orngStat.CA(res, reportSE=1)
14    for i in range(len(names)):
15        print "%s: %5.3f+-%5.3f   " % (names[i], CAs[i][0], 1.96*CAs[i][1]),
16    print
17
18print "\nproportionsTest that will always give the same results"
19for i in range(3):
20    res = orngTest.proportionTest(learners, data, 0.7)
21    printResults(res)
22
23print "\nproportionsTest that will give different results, but the same each time the script is run"
24myRandom = orange.RandomGenerator()
25for i in range(3):
26    res = orngTest.proportionTest(learners, data, 0.7, randomGenerator = myRandom)
27    printResults(res)
28
29if not vars().has_key("NO_RANDOMNESS"):
30    print "\nproportionsTest that will give different results each time it is run"
31    for i in range(3):
32        res = orngTest.proportionTest(learners, data, 0.7, randseed = random.randint(0, 100))
33        printResults(res)
34
35print "\nproportionsTest + storing classifiers"
36res = orngTest.proportionTest(learners, data, 0.7, 100, storeClassifiers = 1)
37print "#iter %i, #classifiers %i" % (len(res.classifiers), len(res.classifiers[0]) if len(res.classifiers) > 0 else -1)
38print
39
40##print "\nLearning with 100% class noise"
41##classnoise = orange.Preprocessor_addClassNoise(proportion=1.0)
42##res = orngTest.proportionTest(learners, data, 0.7, 100, pps = [("L", classnoise)])
43##printResults(res)
44
45print "\nGood old 10-fold cross validation"
46res = orngTest.crossValidation(learners, data)
47printResults(res)
48
49
50print "\nLearning curve"
51prop = orange.frange(0.2, 1.0, 0.2)
52res = orngTest.learningCurveN(learners, data, folds = 5, proportions = prop)
53for i in range(len(prop)):
54    print "%5.3f:" % prop[i],
55    printResults(res[i])
56
57print "\nLearning curve with pre-separated data"
58indices = orange.MakeRandomIndices2(data, p0 = 0.7)
59train = data.select(indices, 0)
60test = data.select(indices, 1)
61res = orngTest.learningCurveWithTestData(learners, train, test, times = 5, proportions = prop)
62for i in range(len(prop)):
63    print "%5.3f:" % prop[i],
64    printResults(res[i])
65
66
67print "\nLearning and testing on pre-separated data"
68res = orngTest.learnAndTestOnTestData(learners, train, test)
69printResults(res)
70
71print "\nLearning and testing on the same data"
72res = orngTest.learnAndTestOnLearnData(learners, data)
73printResults(res)
Note: See TracBrowser for help on using the repository browser.