我创建了一个决策树,并尝试按照一个答案(Visualizing decision tree in scikit-learn)在python中可视化它,但仍然不起作用:import pandas as pd
score_v2 = pd.read_csv("C:/TEST_RF_CSV_simple.csv",encoding = "cp950")
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
score_X = score_v2
score_y = score_v2.buy_lf
X_train, X_test, y_train, y_test = train_test_split(
score_X, score_y, test_size=0.3)
from sklearn.tree import DecisionTreeClassifier
tree=DecisionTreeClassifier(criterion = 'entropy', max_depth=3,
random_state=0)
tree.fit(X_train, y_train)
tree_1 = tree.fit(X_train, y_train)
from sklearn.tree import export_graphviz
dotfile = open("D:/dtree2.dot", 'w')
tree.export_graphviz(dtree, out_file = dotfile, feature_names =
X.columns)
dotfile.close()
我的错误是:
^{pr2}$
有什么大师能帮我解决这个问题吗?在