Please everyone a great god!
The from sklearn import datasets
The from sklearn import tree
The from sklearn. Externals. Six import instead
The import pydot
The import numpy as np
Iris=datasets. Load_iris () # loading iris data set
# load characteristics and the label set
X=[[1, 1], [1, 1], [1, 0], [0, 1], [0, 1]]
X=np. Array (x)
Y=[' 1 ', '1', '0', '0', '0']
Y=np. Array (y)
Z=[' surface ', 'have fins']
P=[' fish ', 'no fish']
P=np. Array (p)
CLF=tree. DecisionTreeClassifier # () to build a decision tree, the default is gini index
# CLF=CLF. Fit (iris data, iris. The target)
CLF=tree. DecisionTreeClassifier ()
CLF=CLF. Fit (x, y)
Dot_data=(https://bbs.csdn.net/topics/StringIO)
Tree. Export_graphviz (CLF out_file=dot_data, feature_names=z, class_names=p, filled=True, rounded=True, special_characters=True)
# tree. Export_graphviz (CLF out_file=dot_data, feature_names=iris. Feature_names, class_names=iris. Target_names, filled=True, rounded=True, special_characters=True)
# tree. Export_graphviz (CLF, out_file=r tree. "dot") # release the this line of code to generate the decision tree of file
(graph)=pydot. Graph_from_dot_data (dot_data. The getvalue ())
Graph. Write_png (' iris. PNG ')