source: orange/docs/reference/rst/code/datatable1.py @ 9927:d6ca7b346864

Revision 9927:d6ca7b346864, 1.1 KB checked in by markotoplak, 2 years ago (diff)

data.variable -> feature.

Line 
1# Description: Shows how to construct an orange.ExampleTable out of nothing
2# Category:    basic classes
3# Classes:     ExampleTable, Domain
4# Uses:       
5# Referenced:  ExampleTable.htm
6
7import Orange
8
9cards = [3, 3, 2, 3, 4, 2]
10values = ["1", "2", "3", "4"]
11
12features = [Orange.feature.Discrete(name, values = values[:card])
13              for name, card in zip("abcdef", cards)]
14classattr = Orange.feature.Discrete("y", values = ["0", "1"])
15domain = Orange.data.Domain(features + [classattr])
16data = Orange.data.Table(domain)
17
18import random
19random.seed(0)
20
21for i in range(5):
22    inst = [random.randint(0, c-1) for c in card]
23    inst.append(inst[0]==inst[1] or inst[4]==0)
24    data.append(inst)
25
26for inst in data:
27    print inst
28
29loe = [["3", "1", "1", "2", "1", "1",  "1"],
30       ["3", "1", "1", "2", "2", "1",  "0"],
31       ["3", "3", "1", "2", "2", "1",  "1"]
32      ]
33
34d2 = Orange.data.Table(domain, loe)
35
36d2[0] = ["1", "1", 1, "1", "1", "1", "1"]
37
38import numpy
39d = Orange.data.Domain([Orange.feature.Continuous('a%i'%x) for x in range(5)])
40a = numpy.array([[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]])
41t = Orange.data.Table(a)
42print len(t)
43print t[0]
44print t[1]
Note: See TracBrowser for help on using the repository browser.