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

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

Tests moved and renamed from orange 20.

Line
1# Description: Demonstrates the use of ContingencyClassAttr
2# Category:    statistics
3# Classes:     Contingency, ContingencyClassAttr
4# Uses:        monk1
5# Referenced:  contingency.htm
6
7import orange
8data = orange.ExampleTable("monk1")
9cont = orange.ContingencyClassAttr("e", data)
10
11print "Inner variable: ", cont.innerVariable.name
12print "Outer variable: ", cont.outerVariable.name
13print
14print "Class variable: ", cont.classVar.name
15print "Attribute:      ", cont.variable.name
16print
17
18print "Distributions:"
19for val in cont.classVar:
20    print "  p(.|%s) = %s" % (val.native(), cont.p_attr(val))
21print
22
23firstvalue = orange.Value(cont.variable, 0)
24firstnative = firstvalue.native()
25print "Probabilities for e='%s'" % firstnative
26for val in cont.classVar:
27    print "  p(%s|%s) = %5.3f" % (firstnative, val.native(), cont.p_attr(firstvalue, val))
28print
29
30cont = orange.ContingencyClassAttr(data.domain["e"], data.domain.classVar)
31for ex in data:
32    cont.add_attrclass(ex["e"], ex.getclass())
33
34print "Distributions from a matrix computed manually:"
35for val in cont.classVar:
36    print "  p(.|%s) = %s" % (val.native(), cont.p_attr(val))
37print
Note: See TracBrowser for help on using the repository browser.