在系统中安装graphviz
brew install graphviz
在shell中测试一下
$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)
在python中安装(切换python3的环境)
pip install graphviz
conda install graphviz
测试import
没有报错 就是成功了
一个测试的栗子
import graphviz
import sklearn.datasets as datasets
import pandas as pd
iris=datasets.load_iris()
df=pd.DataFrame(iris.data, columns=iris.feature_names)
y=iris.target
from sklearn.tree import DecisionTreeClassifier
dtree=DecisionTreeClassifier()
dtree.fit(df,y)
from sklearn.externals.six import StringIO
from IPython.display import Image
from sklearn.tree import export_graphviz
import pydotplus
dot_data=StringIO()
export_graphviz(dtree,out_file=dot_data,filled=True, rounded=True, special_characters=True)
graph=pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())
需要安装一个包
pip install pydotplus
如果成功了,应该是输出一张图