I'm using pandas command tree.DecisionTreeClassifier
to build a (binary) classification tree. Something along the lines of:
我正在使用pandas命令tree.DecisionTreeClassifier来构建(二进制)分类树。有点像:
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 个解决方案
#1
You can find a great solution to this here: https://gist.github.com/cstrelioff/8fefa9a43e82d96e9f0c
你可以在这里找到一个很好的解决方案:https://gist.github.com/cstrelioff/8fefa9a43e82d96e9f0c
#1
You can find a great solution to this here: https://gist.github.com/cstrelioff/8fefa9a43e82d96e9f0c
你可以在这里找到一个很好的解决方案:https://gist.github.com/cstrelioff/8fefa9a43e82d96e9f0c