在Scikit的官網(wǎng)上 ,找到的生成可視化的決策樹的代碼如下:
from IPython.display import Image
import pydotplus
dot_data = sklearn.tree.export_graphviz(clf, out_file=None,
feature_names=iris.feature_names,
class_names=iris.target_names,
filled=True, rounded=True,
special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_pdf("iris.pdf")
運(yùn)行報(bào)錯如下:
pydotplus.graphviz.InvocationException: GraphViz's executables not found
安裝GraphViz可以解決批销。通過 brew install graphviz 命令安裝跷叉。
安裝完成后重啟IDE 旗笔,就可以生成可視化的pdf和png了。