source: orange/docs/reference/rst/code/variable-get_value_from.py @ 9897:092268eeed09

Revision 9897:092268eeed09, 1.0 KB checked in by markotoplak, 2 years ago (diff)

Put old variable documentation Orange.feature.

Line 
1# Description: Construction and computation of new features
2# Category:    core
3# Uses:        monks-1
4# Referenced:  Orange.feature
5# Classes:     Orange.feature.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
15monks = Orange.data.Table("monks-1")
16e2 = Orange.feature.Discrete("e2", values=["not 1", "1"])   
17e2.get_value_from = checkE
18
19print Orange.feature.scoring.InfoGain(e2, monks)
20
21dist = Orange.core.Distribution(e2, monks)
22print dist
23
24# Split the data into training and testing set
25indices = Orange.core.MakeRandomIndices2(monks, p0=0.7)
26train_data = monks.select(indices, 0)
27test_data = monks.select(indices, 1)
28
29# Convert the training set to a new domain
30new_domain = Orange.data.Domain([monks.domain["a"], monks.domain["b"], e2, monks.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.