当我使用GridSearchCV和xgboost执行网格搜索时
kfold = StratifiedKFold(n_splits=3, shuffle=False, random_state=random_state)
model = xgb.XGBClassifier()
grid_search = GridSearchCV(model, param_grid, scoring="roc_auc",
n_jobs=4, cv=kfold, verbose=1)GridSearchCV内部使用的轮数是多少?
发布于 2017-03-10 16:58:28
对于这个问题没有很好的答案,但最好的策略是使用高数字500/1000,甚至是大参数以及early_stopping_rounds参数。CV将继续,直到它在测试折叠上开始过拟合。这就是你从CV中获得足够好的参数(从偏差-方差权衡的角度来看)的时候。在本质上,虽然你可能设置了太多的助推步骤,但可能永远不会有那么多轮的助推。
发布于 2021-09-09 19:02:38
使用best_estimator_属性查找n_estimators参数:
grid_search.best_estimator_输出:
XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=1, eta=0.1, gamma=0,
gpu_id=-1, importance_type='gain', interaction_constraints='',
learning_rate=0.100000001, max_delta_step=0, max_depth=6,
min_child_weight=1, missing=nan, monotone_constraints='()',
n_estimators=100, n_jobs=4, num_parallel_tree=1, random_state=0,
reg_alpha=0, reg_lambda=6, scale_pos_weight=1, subsample=0.8,
tree_method='exact', validate_parameters=1, verbosity=None)您可以使用此命令更改网格搜索中的超参数值:
param_grid = [{'max_depth':[6],
'eta': [0.1],
'subsample': [0.8],
'reg_lambda': [6],
'n_estimators': [10,100,1000]}]
xgb_model = xgb.XGBRegressor()
grid_search = GridSearchCV(xgb_model, param_grid, cv=5, return_train_score=True, scoring = 'neg_mean_squared_error')
grid_search.fit(X_train, y_train)https://stackoverflow.com/questions/41675088
复制相似问题