Programming decision tree
Code: "decision3_id3_animal.py". Programming language: Python DMelt Version 1. Last modified: 11/11/2015. License: Pro
https://datamelt.org/code/cache/decision3_id3_animal_1871.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



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

Ads help maintain this website.