source: orange-bioinformatics/docs/reference/assess3.py @ 1634:32373d957326

Revision 1634:32373d957326, 1.8 KB checked in by mitar, 2 years ago (diff)

Renamed addon reference documentation.

Line 
1import orange
2import obiAssess
3import obiGeneSets
4
5gs = obiGeneSets.collections([":kegg:hsa"])
6data = orange.ExampleTable("DLBCL.tab")
7
8asl = obiAssess.AssessLearner()
9
10def genesetsAsAttributes(data, ass, domain=None):
11    """
12    Construct new data set with gene sets as attributes from data
13    set "data" with assess model "ass".
14    """
15
16    ares = {}
17    for ex in data:
18        cres = ass(ex)
19        for name,val in cres.items():
20            aresl = ares.get(name, [])
21            aresl.append(val)
22            ares[name] = aresl
23
24    ares = sorted(ares.items())
25
26    if not domain: #construct new domain instance if needed
27        domain = orange.Domain([ orange.FloatVariable(name=name) \
28            for name in [ a[0] for a in ares]], data.domain.classVar )
29
30    examples = [ [ b[zap] for a,b in ares ] + \
31        [ data[zap][-1] ]   for zap in range(len(data)) ]
32
33    et = orange.ExampleTable(domain, examples)
34    return et
35
36offer = None
37
38def transformLearningS(data):
39    ass = asl(data, "hsa", geneSets=gs)
40    et = genesetsAsAttributes(data, ass)
41
42    global offer
43    offer = (et.domain, ass) #save assess model
44
45    return et
46   
47def transformTestingS(data):
48    global offer
49    if not offer:
50        a = fdfsdsdd #exception
51
52    domain, ass = offer
53    offer = None
54
55    return genesetsAsAttributes(data, ass, domain)
56
57
58import orngBayes, orngTest, orngStat
59learners = [ orngBayes.BayesLearner() ]
60
61resultsOriginal = orngTest.crossValidation(learners, data, folds=10)
62resultsTransformed = orngTest.crossValidation(learners, data, folds=10, 
63    pps = [("L", transformLearningS), ("T", transformTestingS)])
64
65print "Original", "CA:", orngStat.CA(resultsOriginal), "AUC:", orngStat.AUC(resultsOriginal)
66print "Transformed", "CA:", orngStat.CA(resultsTransformed), "AUC:", orngStat.AUC(resultsTransformed)
67
Note: See TracBrowser for help on using the repository browser.