Python, PyDot and DecisionTree

前端 未结 3 1640
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 11:52

I\'m trying to visualize my DecisionTree, but getting the error The code is:

X = [i[1:] for i in dataset]#attribute
y = [i[0] for i in dataset]
clf = tree.Decisi         


        
3条回答
  •  失恋的感觉
    2021-02-04 12:38

    In case of using Python 3, just use pydotplus instead of pydot. It will also have a soft installation process by pip.

    import pydotplus
    
    
    
    dot_data = StringIO()
    tree.export_graphviz(clf, out_file=dot_data)
    graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
    graph.write_pdf("iris.pdf")
    

提交回复
热议问题