2016-07-08 3 views
1

Windows10에서 IPython을 사용하여 의사 결정 트리를 학습하고 그릴 수 있습니다. 나는 다음의 코드가 리눅스에서 돌아갔다는 것을 알고있다. 나는 pydot를 설치했고 graphviz도 가지고있다.Pydot를 사용하여 그래프를 작성하는 중 속성 오류가 발생했습니다.

# Train and draw out a decision tree 

from IPython import display 
from sklearn import datasets, tree, utils 
from sklearn.externals.six import StringIO 
import pydot 

# Train a small decision tree on the iris dataset 
dataset = datasets.load_iris() 
X_iris, y_iris = utils.shuffle(dataset.data, dataset.target,random_state=42) 
tree_clf = tree.DecisionTreeClassifier(max_depth=3).fit(X_iris, y_iris) 

# Generate a plot of the decision tree 
dot_data = StringIO() 
tree.export_graphviz(tree_clf, out_file=dot_data) 
graph = pydot.graph_from_dot_data(dot_data.getvalue()) 
display.Image(graph.create_png()) 

나는 다음과 같은 오류가 발생합니다 :

--------------------------------------------------------------------------- 
AttributeError       Traceback (most recent call last) 
<ipython-input-5-3452aa5e9794> in <module>() 
    15 tree.export_graphviz(tree_clf, out_file=dot_data) 
    16 graph = pydot.graph_from_dot_data(dot_data.getvalue()) 
---> 17 display.Image(graph.create_png()) 

AttributeError: 'list' object has no attribute 'create_png' 
+0

내가 지정되지 않은 텍스트를 제거한 – Dbz

+0

읽을 수 있도록 출력 형식하세요 - 네, 그것은 dot_data.getvalue에 포함 된 단지 값()이었고,이 시점 – rahul

답변

1

내가 pydotplus에 모든 pydot 명령을 변경하여이 문제를 해결 (import pydotplus 포함)이 pydotplus 패키지를 설치하기 위해 가능한 사용 !pip install pydotplus 수 있습니다..

참조 https://github.com/scikit-learn/scikit-learn/pull/7342/files

+0

에 관련되지 않을 수도 있습니다, 파이썬 3.5에서는이 문제를 해결할 수있는 유일한 방법이었습니다. 감사! –

관련 문제