0

I'm using pandas command tree.DecisionTreeClassifier to build a (binary) classification tree. Something along the lines of:

dcrG = tree.DecisionTreeClassifier(criterion='entropy',splitter='best',options_go_here)
dcrG.fit(train[features], train['G'])

Now that I have succesfully built my decision tree, I would like pandas to print me out the actual decision tree, so something along the lines of

if (var1>0.4) 
  if (var4>3.24)
    if (var2<0.5)
      return 1
    else
      return 0
  else
    return 1
else
  if (var3>3.5)
    if (var2<0.1)
      return 0
    else
      return 1
  else
    if (var2>0.4)
      return 1
    else
      return 0

so that I can export the resulting algorithm to other programming languages. How can I do this?

user1111929
  • 6,050
  • 9
  • 43
  • 73

1 Answers1

0

You can find a great solution to this here: https://gist.github.com/cstrelioff/8fefa9a43e82d96e9f0c

kd88
  • 1,054
  • 10
  • 21