随机深林 使用graphviz进行可视化
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(n_estimators=2, max_depth=2, random_state=1)
rf.fit(x_train, y_train)
# 随机森林画图
i=0
for per_rf in rf.estimators_:
dot_data = tree.export_graphviz(per_rf, out_file=None,
feature_names=x_train.columns,
class_names=['0','1'],
filled=True, rounded=True,
special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)
i = i+1
graph.write_pdf(str(i)+"DTtree.pdf")

浙公网安备 33010602011771号