⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 variable2.py

📁 orange源码 数据挖掘技术
💻 PY
字号:
# 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -