source: orange/orange/doc/ofb/data_characteristics3.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 1.1 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line 
1# Description: Read data, show mean for continuous attributes and contingency matrix for nominal attributes
2# Category:    description
3# Uses:        adult_sample.tab
4# Classes:     DomainContingency
5# Referenced:  basic_exploration.htm
6
7import orange
8data = orange.ExampleTable("../datasets/adult_sample")
9
10print "Continuous attributes:"
11for a in range(len(data.domain.attributes)):
12    if data.domain.attributes[a].varType == orange.VarTypes.Continuous:
13        d = 0.; n = 0
14        for e in data:
15            if not e[a].isSpecial():
16                d += e[a]
17                n += 1
18        print %s, mean=%3.2f" % (data.domain.attributes[a].name, d/n)
19
20print "\nNominal attributes (contingency matrix for classes:", data.domain.classVar.values, ")"
21cont = orange.DomainContingency(data)
22for a in data.domain.attributes:
23    if a.varType == orange.VarTypes.Discrete:
24        print %s:" % a.name
25        for v in range(len(a.values)):
26            sum = 0
27            for cv in cont[a][v]:
28                sum += cv
29            print "    %s, total %d, %s" % (a.values[v], sum, cont[a][v])
30        print
Note: See TracBrowser for help on using the repository browser.