Skip to content

Instantly share code, notes, and snippets.

@ahmedazizkhelifi
Last active July 24, 2020 16:29
Show Gist options
  • Select an option

  • Save ahmedazizkhelifi/16b352ca6d1b985b34266e45a3e5014a to your computer and use it in GitHub Desktop.

Select an option

Save ahmedazizkhelifi/16b352ca6d1b985b34266e45a3e5014a to your computer and use it in GitHub Desktop.
class DecisionNode(Node):
def __init__(self,label,distr,threshold ,left = None,right = None):
Node.__init__(self,label,left,right)
self.threshold = threshold
self.distr = distr
def __str__(self):
L = self.linearize()
s = ""
for e in L:
s += "IF "
for i in range(1,len(e)):
if e[i] == e[i-1].left:
s += "{} >= {} AND ".format(e[i-1].label, str(e[i-1].threshold))
else:
s += "{} < {} AND ".format(e[i-1].label,str(e[i-1].threshold))
s = "{} THEN {} = {} \n".format(s[:len(s) -4],e[len(e)-1].label,str(e[len(e)-1].distr))
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment