Print the code tree png image
according to the book Uehara code execution after an error, search for something, I found out that because an update for Python, usage changed
the original code:
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
Solution one:
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
Solution two: Install pydotplus module
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
Perfect run! ! !