以下代码
from pandas import Series,DataFrame
from sklearn.feature_extraction import DictVectorizer
vec = DictVectorizer()
dict_X_train = x.to_dict(orient='records')
x_train =vec.fit_transform(dict_X_train).toarray()
X_train, X_test, y_train, y_test = train_test_split(x_train, y, test_size = 0.3, random_state = 100)
clf = clf.fit(X_train, y_train)
import pydotplus
from IPython.display import Image
dot_data = tree.export_graphviz(clf, out_file=None,
feature_names=vec.get_feature_names(),
filled=True, rounded=True, proportion=True,
special_characters=False)
graph = pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())