source: orange/docs/tutorial/rst/code/data_characteristics4.py @ 9374:59bac7ddd8a2

Revision 9374:59bac7ddd8a2, 1.1 KB checked in by mitar, 2 years ago (diff)

Tutorial documentation structure.

Line 
1# Description: Show frequences for values of discrete attributes, count number of instances where attribute is not defined
2# Category:    description
3# Uses:        adult_sample.tab
4# Referenced:  basic_exploration.htm
5
6import orange
7data = orange.ExampleTable("../../datasets/adult_sample")
8dist = orange.DomainDistributions(data)
9
10print "Average values and mean square errors:"
11for i in range(len(data.domain.attributes)):
12    if data.domain.attributes[i].varType == orange.VarTypes.Continuous:
13        print "%s, mean=%5.2f +- %5.2f" % \
14          (data.domain.attributes[i].name, dist[i].average(), dist[i].error())
15
16print "\nFrequencies for values of discrete attributes:"
17for i in range(len(data.domain.attributes)):
18    a = data.domain.attributes[i]
19    if a.varType == orange.VarTypes.Discrete:
20        print "%s:" % a.name
21        for j in range(len(a.values)):
22            print %s: %d" % (a.values[j], int(dist[i][j]))
23
24print "\nNumber of instances where attribute is not defined:"
25for i in range(len(data.domain.attributes)):
26    a = data.domain.attributes[i]
27    print %2d %s" % (dist[i].unknowns, a.name)
Note: See TracBrowser for help on using the repository browser.