variable2.py
来自「orange源码 数据挖掘技术」· Python 代码 · 共 29 行
PY
29 行
# Description: Shows how to construct new attributes from the existing and use it seamlessly in sampling and testing
# Category: feature construction, constructive induction
# Classes: Variable, MakeRandomIndices2
# Uses: monk1
# Referenced: Variable.htm
import orange, orngTree
data = orange.ExampleTable("monk1")
indices = orange.MakeRandomIndices2(data, p0=0.7)
trainData = data.select(indices, 0)
testData = data.select(indices, 1)
e2 = orange.EnumVariable("e2", values = ["not 1", "1"])
e2.getValueFrom = lambda example, returnWhat: \
orange.Value(e2, example["e"]=="1")
newDomain = orange.Domain([data.domain["a"], data.domain["b"], e2, data.domain.classVar])
newTrain = orange.ExampleTable(newDomain, trainData)
tree = orange.TreeLearner(newTrain)
orngTree.printTxt(tree)
for ex in testData[:10]:
print ex.getclass(), tree(ex)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?