本文介绍了得到大 pandas 的实际决策树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用熊猫命令 tree.DecisionTreeClassifier 来构建(二进制)分类树。类似于以下内容:

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?

推荐答案

您可以在这里找到一个很好的解决方案:

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

这篇关于得到大 pandas 的实际决策树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 20:02