from sklearn.model_selection import StratifiedKFold #交叉验证
from sklearn.model_selection import GridSearchCV #网格搜索
pat= {'splitter':('best','random'),
'criterion':('gini','entropy'),
'max_depth':[*range(1,10)],
'min_samples_leaf':[*range(1,15,2)],
'max_leaf_nodes':[*range(2,15,2)],
'min_samples_split':[*range(2,15,2)],
}
clf = DecisionTreeClassifier(random_state=66)
GS = GridSearchCV(clf,pat,cv=10)
GS.fit(X_train, y_train)
print(GS.best_params_) #最优值
print(GS.best_score_) #最优结果