我想绘制一个随机森林的决策树。因此,我编写了以下代码:
我想绘制一个随机森林的决策树。因此,我编写了以下代码:
clf = RandomForestClassifier(n_estimators=100)
import pydotplus
import six
from sklearn import tree
dotfile = six.StringIO()
i_tree = 0
for tree_in_forest in clf.estimators_:
if (i_tree <1):
tree.export_graphviz(tree_in_forest, out_file=dotfile)
pydotplus.graph_from_dot_data(dotfile.getvalue()).write_png('dtree'+ str(i_tree) +'.png')
i_tree = i_tree + 1
但它并没有生成任何东西.. 你有想法如何从随机森林中绘制决策树吗?
clf.estimators_
的一个元素。 - user6903745