上课时候teacher用pycharm运行出来了我用jupyter notebook运行没反应
代码如下:
from sklearn.datasets import load_iris
from sklearn import tree
import pydotplus
iris = load_iris()
X = iris.data
y = iris.target
clf = tree.DecisionTreeClassifier(max_depth=4)
clf = clf.fit(X, y)
dot_data = tree.export_graphviz(clf, out_file=None,
class_names=iris.target_names,
filled=True, rounded=True,
special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)
f = open('tree.png','wb')
#f = open('tree.pdf', 'wb')
f.write(graph.create_png())
#f.write(graph.create_pdf())
f.close()