| Rev | Line | |
|---|
| [6866] | 1 | # Description: Learn decision tree from data and output class probabilities for first few instances |
|---|
| 2 | # Category: modelling |
|---|
| 3 | # Uses: voting.tab |
|---|
| 4 | # Classes: orngTree.TreeLearner |
|---|
| 5 | # Referenced: c_otherclass.htm |
|---|
| 6 | |
|---|
| 7 | import orange, orngTree |
|---|
| 8 | data = orange.ExampleTable("voting") |
|---|
| 9 | |
|---|
| 10 | tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2) |
|---|
| 11 | print "Possible classes:", data.domain.classVar.values |
|---|
| 12 | print "Probabilities for democrats:" |
|---|
| 13 | for i in range(5): |
|---|
| 14 | p = tree(data[i], orange.GetProbabilities) |
|---|
| 15 | print "%d: %5.3f (originally %s)" % (i+1, p[1], data[i].getclass()) |
|---|
| 16 | |
|---|
| 17 | print |
|---|
| 18 | orngTree.printTxt(tree) |
|---|
| 19 | orngTree.printDot(tree, fileName='tree.dot', internalNodeShape="ellipse", leafShape="box") |
|---|
| 20 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.