【代码模版】graphviz与pydotplus绘制决策树

需要提前安装的:
brew : graphviz (for mac)
pip : pydotplus

# visualization model
from sklearn import tree
dot_data = \
    tree.export_graphviz(
        dtc,  # 此处按照需要修改model name
        out_file = None,
        feature_names = list(X.columns),  # DataFrame.columns获得数据框特征名称,此处需要list格式
        filled = True,
        impurity = False,
        rounded = True
    )
import pydotplus
graph = pydotplus.graph_from_dot_data(dot_data)
graph.get_nodes()[7].set_fillcolor("#FFF2DD")
from IPython.display import Image
Image(graph.create_png())
# graph.write_png("dtc_white_background.png")  # 此处按照需要填写要保存的file_path
发布了22 篇原创文章 · 获赞 0 · 访问量 940

猜你喜欢

转载自blog.csdn.net/weixin_44680262/article/details/104498268