source: orange/orange/doc/Orange/rst/code/c45.py @ 7739:369736292db8

Revision 7739:369736292db8, 1.1 KB checked in by markotoplak, 3 years ago (diff)

Made python wrappers around C45Learner + Classfiers (this enables to implement dump() as a method of the classifier).

Line 
1import Orange, orange
2
3data = orange.ExampleTable("iris")
4tree = Orange.classification.tree.C45Learner(data)
5
6print "\n\nC4.5 with default arguments"
7for i in data[:5]:
8    print tree(i), i.getclass()
9
10print "\n\nC4.5 with m=100"
11tree = Orange.classification.tree.C45Learner(data, m=100)
12for i in data[:5]:
13    print tree(i), i.getclass()
14
15print "\n\nC4.5 with minObjs=100"
16tree = Orange.classification.tree.C45Learner(data, minObjs=100)
17for i in data[:5]:
18    print tree(i), i.getclass()
19
20print "\n\nC4.5 with -m 1 and -s"
21lrn = Orange.classification.tree.C45Learner()
22lrn.commandline("-m 1 -s")
23tree = lrn(data)
24for i in data:
25    if i.getclass() != tree(i):
26        print i, tree(i)
27
28
29tree = Orange.classification.tree.C45Learner(data)
30print tree.dump()
31print
32
33import orngStat, orngTest
34res = orngTest.crossValidation([ Orange.classification.tree.C45Learner(),  Orange.classification.tree.C45Learner(convertToOrange=1)], data)
35print "Classification accuracy: %5.3f (converted to tree: %5.3f)" % tuple(orngStat.CA(res))
36print "Brier score: %5.3f (converted to tree: %5.3f)" % tuple(orngStat.BrierScore(res))
Note: See TracBrowser for help on using the repository browser.