Graphviz、pydotplus绘制梯度提升树结构图
Graphviz、pydotplus绘制梯度提升树结构图
安装
- pip install pydotplus
- 安装Graphviz。https://blog.****.net/a1368783069/article/details/52067404
# 梯度提升树结构图
from sklearn import tree
import pydotplus
# 绘制前十颗树,并保存为png
# clf = ensemble.GradientBoostingRegressor(**params) ,模型训练部分省略
for i in range(0,10):
sub_tree = clf.estimators_[i, 0]
dot_data = tree.export_graphviz(
sub_tree,
out_file=None, filled=True,
rounded=True,
special_characters=True,
proportion=True,
)
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_png("tree"+str(i)+".png")