source: orange/docs/reference/rst/code/variable-get_value_from.py @ 9372:aef193695ea9

Revision 9372:aef193695ea9, 1.1 KB checked in by mitar, 2 years ago (diff)

Moved documentation to the separate directory.

Line 
1# Description: Construction and computation of new features
2# Category:    core
3# Uses:        monks-1
4# Referenced:  Orange.data.variable
5# Classes:     Orange.data.variable.Discrete
6
7import Orange
8
9def checkE(inst, return_what):
10    if inst["e"]=="1": 
11        return e2("1")
12    else:
13        return e2("not 1") 
14
15data = Orange.data.Table("monks-1")
16e2 = Orange.data.variable.Discrete("e2", values=["not 1", "1"])   
17e2.get_value_from = checkE
18
19print Orange.core.MeasureAttribute_info(e2, data)
20
21dist = Orange.core.Distribution(e2, data)
22print dist
23
24# Split the data into training and testing set
25indices = Orange.core.MakeRandomIndices2(data, p0=0.7)
26train_data = data.select(indices, 0)
27test_data = data.select(indices, 1)
28
29# Convert the training set to a new domain
30new_domain = Orange.data.Domain([data.domain["a"], data.domain["b"], e2, data.domain.class_var])
31new_train = Orange.data.Table(new_domain, train_data)
32
33# Construct a tree and classify unmodified instances
34tree = Orange.core.TreeLearner(new_train)
35for ex in test_data[:10]:
36    print ex.getclass(), tree(ex)
Note: See TracBrowser for help on using the repository browser.