from sklearn.datasets import load_iris import pydotplus from IPython.display import Image from sklearn import tree #训练模型 iris=load_iris() clf=tree.DecisionTreeClassifier() clf=clf.fit(iris.data,iris.target) #绘图 dot_data=tree.export_graphviz(decision_tree=clf, out_file=None, rounded=True, filled=True, feature_names=iris.feature_names) graph=pydotplus.graph_from_dot_data(dot_data) Image(graph.create_png())