get the actual decision tree in pandas

孤者浪人 提交于 2019-12-24 21:32:37

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/30146532/get-the-actual-decision-tree-in-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!