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

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

Made XPM version of the icon 32x32.

Line 
1# Description: Read data, output class values and attribute names, and show class distribution (in proportion of instances belonging to a class)
2# Category:    description
3# Uses:        adult_sample.tab
4# Referenced:  basic_exploration.htm
5
6import orange
7data = orange.ExampleTable("../datasets/adult_sample")
8print "Classes:", len(data.domain.classVar.values)
9print "Attributes:", len(data.domain.attributes), ",",
10
11# count number of continuous and discrete attributes
12ncont=0; ndisc=0
13for a in data.domain.attributes:
14    if a.varType == orange.VarTypes.Discrete:
15        ndisc = ndisc + 1
16    else:
17        ncont = ncont + 1
18print ncont, "continuous,", ndisc, "discrete"
19
20# obtain class distribution
21c = [0] * len(data.domain.classVar.values)
22for e in data:
23    c[int(e.getclass())] += 1
24print "Instances: ", len(data), "total",
25r = [0.] * len(c)
26for i in range(len(c)):
27    r[i] = c[i]*100./len(data)
28for i in range(len(data.domain.classVar.values)):
29    print ", %d(%4.1f%s) with class %s" % (c[i], r[i], '%', data.domain.classVar.values[i]),
30print
Note: See TracBrowser for help on using the repository browser.