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

📄 cb-stopcriteria.py

📁 orange源码 数据挖掘技术
💻 PY
字号:
# Description: Shows how to derive a Python class from orange.TreeStopCriteria
# Category:    classification, callbacks to Python
# Classes:     TreeStopCriteria
# Uses:        lenses
# Referenced:  callbacks.htm

import orange, orngMisc, orngTree

data = orange.ExampleTable("lenses")

from random import randint, seed
seed(0)

defStop = orange.TreeStopCriteria()
treeLearner = orange.TreeLearner()
treeLearner.stop = lambda exs, wID, cont: defStop(exs, wID, cont) or randint(1, 5)==1

print "\n\nTree build with stop criteria as a function"
tree = treeLearner(data)
orngTree.printTxt(tree)

class StoppingCriterion_random(orange.TreeStopCriteria):
  def __call__(self, gen, weightID, contingency):
    return orange.TreeStopCriteria.__call__(self, gen, weightID, contingency) \
           or randint(1, 5)==1

print "\n\nTree build with stop criteria as a class"
treeLearner.stop = StoppingCriterion_random()
tree = treeLearner(data)
orngTree.printTxt(tree)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -