コードツリーのPNG画像を印刷
エラーが発生した後の本上原のコードの実行に応じて、何かを探し、私は、Pythonのアップデートので、使用量が変化していることが分かった
元のコードを:
titanic.estimator.decision_tree_classifier(criterion='entropy',max_depth=3)
clf = titanic.fit()
dotfile = StringIO()
tree.export_graphviz(clf,out_file=dotfile,feature_names=titanic.df.columns[1:])
pydot.graph_from_dot_data(dotfile.getvalue()).write_png('dtree.png')
!open dtree.png
解決策1:
titanic.estimator.decision_tree_classifier(criterion='entropy',max_depth=3)
clf = titanic.fit()
dotfile = StringIO()
tree.export_graphviz(clf,out_file=dotfile,feature_names=titanic.df.columns[1:])
graph = pydot.graph_from_dot_data(dotfile.getvalue())
graph[0].write_png('dtree.png')
!open dtree.png
対処方法2:pydotplusモジュールをインストールします。
import pydotplus
titanic.estimator.decision_tree_classifier(criterion='entropy',max_depth=3)
clf = titanic.fit()
dotfile = StringIO()
tree.export_graphviz(clf,out_file=dotfile,feature_names=titanic.df.columns[1:])
pydot.graph_from_dot_data(dotfile.getvalue()).write_png('dtree.png')
!open dtree.png
パーフェクトラン!!!