老师,不知道是否可以提供一下源码呢?
其实最好自己敲一遍
def main(): from sklearn.datasets import load_iris iris = load_iris() print(iris) print(len(iris["data"])) from sklearn.model_selection import train_test_split train_data,test_data,train_target,test_target=train_test_split(iris.data,iris.target,test_size=0.2,random_state=1) from sklearn import tree #决策树 clf = tree.DecisionTreeClassifier(criterion="entropy") clf.fit(train_data,train_target) y_pred = clf.predict(test_data) #Verify from sklearn import metrics print(metrics.accuracy_score(y_true=test_target,y_pred=y_pred)) print(metrics.confusion_matrix(y_true=test_target,y_pred=y_pred)) with open("D:/test/test.xlsx","w") as f: tree.export_graphviz(clf,out_file=f) if __name__=="__main__": main()
自己敲一遍