我正在尝试使用来自 scikit-learn 的 iris 数据集训练决策树。我尝试运行以下命令:
from sklearn.datasets import load_iris
from sklearn import tree
clf = tree.DecisionTreeClassifier()
iris = load_iris()
clf = clf.fit(iris.data, iris.target)
tree.export_graphviz(clf,out_file='tree.dot')
from sklearn.externals.six import StringIO
import pydot
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
我收到以下错误:
TypeError: startswith first arg must be str or a tuple of str, not bytes
有人可以帮我解决这个问题吗。谢谢
回溯我得到的错误
() ----> 1 graph = pydot.graph_from_dot_data(dot_data.getvalue()) 中的 TypeError Traceback (最近一次调用最后一次)
C:\Users\Priya\Anaconda3\Lib\site-packages\pydot.py 在 graph_from_dot_data(data)
第218话 第219话
--> 220 返回 dot_parser.parse_dot_data(data) 221 222
C:\Users\Priya\Anaconda3\Lib\site-packages\dot_parser.py 在 parse_dot_data(data)
第508章 509
--> 510 if data.startswith(codecs.BOM_UTF8): 511 data = data.decode('utf-8') 512
TypeError: startswith first arg must be str or a tuple of str, not bytes