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

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

data.variable -> feature.

Line 
1# Description: Shows how to construct and use classifiers by lookup table to construct new features from the existing
2# Category:    classification, lookup classifiers, constructive induction, feature construction
3# Classes:     ClassifierByLookupTable, ClassifierByLookupTable1, ClassifierByLookupTable2, ClassifierByLookupTable3
4# Uses:        monks-1
5# Referenced:  lookup.htm
6
7import Orange
8
9monks = Orange.data.Table("monks-1")
10
11a, b, e = monks.domain["a"], monks.domain["b"], monks.domain["e"]
12
13ab = Orange.feature.Discrete("a==b", values = ["no", "yes"])
14ab.get_value_from = Orange.classification.lookup.ClassifierByLookupTable(ab, a, b,
15                    ["yes", "no", "no",  "no", "yes", "no",  "no", "no", "yes"])
16
17e1 = Orange.feature.Discrete("e==1", values = ["no", "yes"])
18e1.get_value_from = Orange.classification.lookup.ClassifierByLookupTable(e1, e,
19                    ["yes", "no", "no", "no", "?"])
20
21monks2 = monks.select([a, b, ab, e, e1, monks.domain.class_var])
22
23for i in range(5):
24    print monks2.random_example()
25
26for i in range(5):
27    ex = monks.random_example()
28    print "%s: ab %i, e1 %i " % (ex, ab.get_value_from.get_index(ex),
29                                 e1.get_value_from.get_index(ex))
30   
31# What follows is only for testing Orange...
32
33ab_c = ab.get_value_from
34print ab_c.variable1.name, ab_c.variable2.name, ab_c.class_var.name
35print ab_c.no_of_values1, ab_c.no_of_values2
36print [x.name for x in ab_c.variables]
37
38e1_c = e1.get_value_from
39print e1_c.variable1.name, e1_c.class_var.name
40print [x.name for x in e1_c.variables]
Note: See TracBrowser for help on using the repository browser.