我想绘制一个随机森林的决策树。所以,我创建了以下代码:
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
但它不会产生任何东西。。 你知道如何从随机森林中绘制决策树吗?
谢谢你
可以绘制一棵树:
你可以这样看每棵树
假设你的随机森林模型已经拟合好了, 首先,您应该首先导入
export_graphviz
函数:在for循环中,可以执行以下操作来生成
dot
文件下一行生成一个png文件
相关问题 更多 >
编程相关推荐