source: orange/Orange/doc/ofb/data_characteristics.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 906 bytes checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1# Description: Read data, output class values and attribute names, and show class distribution
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",
25for i in range(len(data.domain.classVar.values)):
26    print ",", c[i], "with class", data.domain.classVar.values[i],
27print
Note: See TracBrowser for help on using the repository browser.