tree4.py

来自「orange源码 数据挖掘技术」· Python 代码 · 共 35 行

PY
35
字号
# Author:      J Zabkar
# Version:     1.0
# Description: Storing and printing out the examples in classification tree
# Category:    modelling
# Uses:        iris.tab
# Referenced:   orngTree.htm

import orange, orngTree

def printExamples(node):
    if node:
        if node.branches:
            for b in node.branches:
                printExamples(b)
        else:
            print "----------------- NEW NODE -----------------"
            for ex in node.examples:
                print ex
    else:
        print "null node"


data = orange.ExampleTable("iris.tab")
print len(data)

tree = orngTree.TreeLearner(data, storeExamples=1, storeContingencies=1)
print 'CLASSIFICATION TREE:'
orngTree.printTxt(tree)

print '\nEXAMPLES IN NODES:'
printExamples(tree.tree)

print '\nCONTINGENCY:'
print tree.tree.contingency.classes

⌨️ 快捷键说明

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