运行到最后一步提示报错
from sklearn.model_selection import train_test_split
from sklearn.datasets.california_housing import fetch_california_housing
import pydotplus
from IPython.display import Image
import graphviz
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import os
os.environ["PATH"] += os.pathsep +"D:\anaconda\Library\bin"
import pandas as pd
loan = pd.read_csv('../data/small_loan_processing.csv',encoding='utf-8')
broadband = pd.read_csv('../data/broadband_processing.csv',encoding='utf-8')
#data = loan.copy()
data = broadband.copy()
print(data.head())
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(data.drop('y',axis=1), data['y'], test_size=0.2, random_state=0)
# 建模
# criterion{"gini", "entropy"}, default="gini"
# min_samples_split, default=2 (The minimum number of samples required to split an internal node)
dtc = DecisionTreeClassifier(max_depth=9, criterion='gini', random_state=0)
dtc.fit(x_train, y_train)
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix,classification_report,plot_roc_curve
y_pred = dtc.predict(x_train)
print('train\nconfusion_matrix\n', confusion_matrix(y_true=y_train, y_pred=y_pred))
print('classification report\n',classification_report(y_true=y_train, y_pred=y_pred))
y_pred = dtc.predict(x_test)
print('test\nconfusion_matrix\n', confusion_matrix(y_true=y_test, y_pred=y_pred))
print('classification report\n',classification_report(y_true=y_test, y_pred=y_pred))
plot_roc_curve(dtc, x_train, y_train, color='blue')
ax = plt.gca()
plot_roc_curve(dtc, x_test, y_test, ax=ax, color='red')
plt.show()
from sklearn.tree import export_graphviz
from IPython.display import display,Image
import pydotplus
import numpy as np
import os
os.environ["PATH"] += os.pathsep + '../D:\anaconda\Library\bin'dot_tree = export_graphviz(dtc, out_file=None, feature_names=x_train.columns, class_names=str(np.unique(y_train)),filled=True, rounded=True, special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_tree)
graph.write_png("dtc.png")