source: orange/Orange/testing/regression/tests_20/reference_matrix.py @ 10010:e00de9a885c8

Revision 10010:e00de9a885c8, 2.1 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Fixed some tests.

Line 
1# Description: Shows how to convert ExampleTable into matrices
2# Category:    basic classes, preprocessing
3# Classes:     ExampleTable
4# Uses:        iris, heart_disease
5# Referenced:  ExampleTable.htm
6
7import orange
8
9data = orange.ExampleTable("../datasets/iris")
10
11for meth in [data.toNumeric, data.toNumarray, data.toNumpy]:
12    try:
13        a, c, w = meth()
14        print type(a), type(c), type(w)
15        print a.shape, c.shape
16        print a[:5]
17        print c[:5]
18        print "\n\n"
19    except:
20        print "Call '%s' failed" % meth.__name__
21
22a, c, w = data.toNumpy("1A/cw")
23print type(a), type(w)
24print a.shape
25print a[130]
26print "\n\n\n\n\n"
27
28a, = data.toNumpy("ca1cc0")
29print type(a)
30print a.shape
31print a[130]
32print "\n\n\n\n\n"
33
34
35data_h = orange.ExampleTable("../datasets/heart_disease")
36try:
37    a, c, w = data_h.toNumpy()
38except:
39    print "Converting heart_disease with toNumpy failed (as it should)"
40
41for meth in [data_h.toNumericMA, data_h.toNumarrayMA, data_h.toNumpyMA]:
42    try:
43        a, c, w = meth()
44        print type(a)
45        print a[0]
46    except:
47        print "Call '%s' failed" % meth.__name__
48
49
50
51for meth in [data.toNumeric, data.toNumarray, data.toNumpy]:
52    try:
53        a = meth("ac")[0]
54        t2 = orange.ExampleTable(a)
55        print t2.domain.attributes, t2.domain.classVar
56        print t2[0]
57
58        t3 = orange.ExampleTable(data.domain, a)
59        print t3.domain.attributes, t3.domain.classVar
60        print t3[0]
61
62        columns = "sep length", "sep width", "pet length", "pet width"
63        classValues = "setosa", "versicolor", "virginica"
64        d4 = orange.Domain(map(orange.FloatVariable, columns),
65                           orange.EnumVariable("type", values=classValues))
66        t4 = orange.ExampleTable(d4, a)
67        print t4.domain.attributes, t4.domain.classVar
68        print t4[0]
69
70        print
71    except:
72        print "Exception thrown for '%s'\n" % meth.__name__
73
74zoo = orange.ExampleTable("../datasets/zoo")
75zoo_s = orange.ExampleTable(orange.Domain(zoo.domain.attributes + zoo.domain.getmetas().values(), zoo.domain.classVar), zoo)
76n = zoo_s.toNumpy()
77print n[0]
Note: See TracBrowser for help on using the repository browser.