def test_domainContingency(self): d = orange.ExampleTable("zoo") dc = orange.DomainContingency(d) cd = orange.get_class_distribution(d) for i, c in enumerate(dc): self.assertEqual(id(d.domain.attributes[i]), id(c.outer_variable)) self.assertEqual(id(dc[d.domain.attributes[i]]), id(c)) self.assertFalse(dc.class_is_outer) self.assertEqual(dc.classes, cd) dc.normalize() self.assertEqual(sum(dc[0][0]), 1) dc.foo = 42 s = pickle.dumps(dc) dc2 = pickle.loads(s) self.assertEqual(dc2.foo, dc.foo) self.assertEqual(dc2.classes, dc.classes) self.assertEqual(dc2[0].outer_variable, dc[0].outer_variable)
# Description: Demonstrates the use of DomainContingency # Category: statistics # Classes: DomainContingency, ContingencyClassAttr, ContingencyAttrClass # Uses: monk1 # Referenced: contingency.htm import orange data = orange.ExampleTable("monk1") print "Distributions of classes given the attribute value" dc = orange.DomainContingency(data) print "a: ", dc["a"] print "b: ", dc["b"] print "c: ", dc["e"] print print "Distributions of attribute values given the class value" dc = orange.DomainContingency(data, classIsOuter=1) print "a: ", dc["a"] print "b: ", dc["b"] print "c: ", dc["e"] print
# Description: Read data, show mean for continuous attributes and contingency matrix for nominal attributes # Category: description # Uses: adult_sample.tab # Classes: DomainContingency # Referenced: basic_exploration.htm import orange data = orange.ExampleTable("adult_sample.tab") print "Continuous attributes:" for a in range(len(data.domain.attributes)): if data.domain.attributes[a].varType == orange.VarTypes.Continuous: d = 0.; n = 0 for e in data: if not e[a].isSpecial(): d += e[a] n += 1 print " %s, mean=%3.2f" % (data.domain.attributes[a].name, d / n) print "\nNominal attributes (contingency matrix for classes:", data.domain.classVar.values, ")" cont = orange.DomainContingency(data) for a in data.domain.attributes: if a.varType == orange.VarTypes.Discrete: print " %s:" % a.name for v in range(len(a.values)): sum = 0 for cv in cont[a][v]: sum += cv print " %s, total %d, %s" % (a.values[v], sum, cont[a][v]) print