【问题标题】:number of rounds xgboost in GridSearchCVGridSearchCV 中的 xgboost 轮数
【发布时间】:2017-05-31 05:09:17
【问题描述】:

当我使用 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 内部使用的轮数是多少?

【问题讨论】:

  • 你能解释一下你所说的回合是什么意思吗?您是指每次运行所需的交叉验证步骤数吗?或者它尝试了多少种不同的排列?
  • @dataprincess 以上都不是...是分类器的参数...表示boosting的轮数
  • @dataprincess 我想知道运行GridSearchCV时这个参数的设置是什么
  • 啊,nrounds。这不包含在您的网格搜索的参数空间中吗?我的意思是,你有没有办法自己设定一个范围?这就是我认为它会受到控制的方式。

标签: python scikit-learn xgboost grid-search


【解决方案1】:

对此没有好的答案,但最好的策略是使用大数字 500/1000 甚至大数字以及 early_stopping_rounds 参数。 CV 将继续,直到它开始在测试折叠上过度拟合。那时您将从 CV 中获得足够好的参数(从偏差-方差权衡的角度来看)。从本质上讲,尽管您可能设置了太多的提升步骤,但可能永远不会在那么多轮次中发生提升。

【讨论】:

  • 我的问题是关于 GridSearchCV 内部使用的轮数
【解决方案2】:

使用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)

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 2017-08-17
    • 2017-09-18
    • 2020-01-03
    • 2018-03-27
    • 2017-02-24
    • 2021-11-24
    • 1970-01-01
    • 2021-08-22
    相关资源
    最近更新 更多