Season 1 아카이브/프로그래밍
                
              list object has no attribute write_png
                문장전달자
                 2016. 11. 22. 19:43
              
              
                    
        728x90
    
    
  pydot, graphviz 사용시 아래와 같은 에러가 발생하는 경우
AttributeError : 'list' object has no attribute 'write_png' 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  | >>> import pydot,StringIO >>>  >>> dot_data = StringIO.StringIO()  >>>  >>> tree.export_graphviz(clf, out_file=dot_data,feature_names=['age','sex','1st_class','2nd_class','3rd_class'])  >>>  >>> graph = pydot.graph_from_dot_data(dot_data.getvalue())  >>>  >>> graph.write_png('titanic.png')  >>>  >>> from IPython.core.display import Image  >>>  >>> Image(filename='titanic.png') ------------------------------------------------------------ AttributeError             Traceback (most recent call last) <ipython-input-17-0effc3f1d020> in <module>()       3 tree.export_graphviz(clf, out_file=dot_data,feature_names=['age','sex','1st_class','2nd_class','3rd_class'])       4 graph = pydot.graph_from_dot_data(dot_data.getvalue()) ----> 5 graph.write_png('titanic.png')       6 from IPython.core.display import Image       7 Image(filename='titanic.png') AttributeError: 'list' object has no attribute 'write_png'  | cs | 
pydot 대신 pydotplus 를 설치하면 사용하면 된다.
1  | pip install pydotplus  | cs | 
1 2 3 4 5 6 7  | >>> import pydotplus,StringIO >>> dot_data = StringIO.StringIO()  >>> tree.export_graphviz(clf, out_file=dot_data,feature_names=['age','sex','1st_class','2nd_class','3rd_class'])  >>> graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  >>> graph.write_png('titanic.png')  >>> from IPython.core.display import Image  >>> Image(filename='titanic.png')  | cs | 
728x90