DMelt:AI/Decision Tree

From HandWiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Member

Decision tree

Decision tree uses a tree-like graph or model of decisions and their possible consequences, including chance event outcomes. DMelt supports a number of algorithms implemented in Java to build decision trees.

Let us construct a decision tree using the Python syntax:

from jhpro.dtree import *


dt=DecisionTree()
dt.createRoot(1,"Does animal eat meat?")
dt.addYesNode(1,2,"Does animal have stripes?")
dt.addNoNode(1,3,"Does animal have stripes?")
dt.addYesNode(2,4,"Animal is a Tiger")
dt.addNoNode(2,5,"Animal is a Leopard")
dt.addYesNode(3,6,"Animal is a Zebra")
dt.addNoNode(3,7,"Animal is a Horse")

print dt.outputBinTree() # print its structure 

c=dt.queryBinTree(dt.rootNode)
print c.toString()

c=dt.queryBinTree(c.yesBranch) # set Yes
print c.toString()

c=dt.queryBinTree(c.yesBranch) # set Yes 
print c.getNodeAnswer()        # get node answer 
print c.toString()             # print answer