最近XGBoost调参时发现这个问题,解决后记录一下。
from sklearn.model_selection import GridSearchCV
import xgboost as xgb
from sklearn.metrics import classification_report, roc_curve, auc, confusion_matrix, recall_score, precision_score, f1_score, roc_auc_score, make_scorer
param_test1 = {
'max_depth': [i for i in range(3, 10, 2)],
'min_child_weight': [i for i in range(1, 6, 2)]
}
gsearch = GridSearchCV(
estimator=xgb.XGBClassifier(
learning_rate=0.1,
n_estimators=140,
max_depth=5,
min_child_weight=1,
gamma=0,
subsample=0.8,
colsample_bytree=0.8,
nthread=4,
scale_pos_weight=1,
seed=27),
param_grid=param_test1,
scoring='roc_auc',
cv=5)
gsearch.fit(X_train, y_train)
y_pred = gsearch.predict(X_test)
print('max_depth, min_child_weight')
print('Best